0% found this document useful (0 votes)
41 views2 pages

Design Patterns Are Proven, Reusabl

Uploaded by

bitran paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Design Patterns Are Proven, Reusabl

Uploaded by

bitran paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Design patterns are proven, reusable solutions to common problems in software

design. They provide best practices and templates that developers can follow to
structure code efficiently and maintainably. Below is an overview of the main
categories and popular design patterns:
Types of Design Patterns

Creational Patterns
These patterns deal with object creation mechanisms, trying to create objects
in a manner suitable to the situation.
Singleton: Ensures a class has only one instance and provides a global
point of access to it.
Factory Method: Defines an interface for creating objects, but lets
subclasses alter the type of objects that will be created.
Abstract Factory: Provides an interface for creating families of related or
dependent objects without specifying their concrete classes.
Builder: Separates the construction of a complex object from its
representation.
Prototype: Creates a new object by copying an existing one.

Structural Patterns
These patterns deal with the composition of objects to form larger structures.
Adapter: Allows incompatible interfaces to work together by wrapping an
object.
Bridge: Decouples an abstraction from its implementation so the two can
vary independently.
Composite: Composes objects into tree structures to represent part-whole
hierarchies.
Decorator: Adds new functionality to objects dynamically without altering
their structure.
Facade: Provides a simplified interface to a complex system of classes.
Flyweight: Reduces the cost of creating and managing a large number of
similar objects.
Proxy: Provides a placeholder or surrogate to control access to another
object.

Behavioral Patterns
These patterns focus on communication between objects, making the interaction
flexible and easier to extend.
Observer: Defines a one-to-many dependency so that when one object changes
state, all its dependents are notified.
Strategy: Allows a family of algorithms to be defined and made
interchangeable.
Command: Encapsulates a request as an object, allowing parameterization and
queuing of requests.
Chain of Responsibility: Passes a request along a chain of handlers until
it is processed.
State: Allows an object to change its behavior when its internal state
changes.
Template Method: Defines the skeleton of an algorithm, letting subclasses
redefine certain steps.
Mediator: Reduces the dependencies between communicating objects by
centralizing communication.
Visitor: Lets you add operations to a set of objects without modifying
their classes.
Memento: Captures and restores an object's internal state without violating
encapsulation.
Interpreter: Implements a specialized language or grammar to interpret
sentences.
When to Use Design Patterns

Scalability: Use patterns like Factory Method or Abstract Factory when dealing
with multiple object types that need to grow.
Decoupling: Apply Observer or Mediator to reduce dependencies between
components.
Code Reusability and Flexibility: Utilize Decorator or Strategy patterns to
extend behavior without modifying code.
Performance Optimization: Use Flyweight to save memory with a large number of
similar objects.

Example Use Case: Singleton Pattern

Problem: You need to ensure that only one instance of a configuration class exists
and provide global access to it.

Solution: Use the Singleton pattern.

java

public class Configuration {


private static Configuration instance;

private Configuration() {
// Private constructor to prevent instantiation
}

public static synchronized Configuration getInstance() {


if (instance == null) {
instance = new Configuration();
}
return instance;
}
}

Application in Your Work

API Development: Use the Facade pattern to hide the complexities of multiple
back-end services behind a unified API.
MuleSoft Migration: Apply the Adapter pattern to manage different versions of
services as you migrate to Java 17.
Retail/Eyewear Industry: Implement Observer to notify customers in real-time
about inventory or discounts.

You might also like