Sitemap
Pawan Gupta

Pawan Gupta

#TechEnthusiast #Programmer #Blogger

Design Patterns

6 min readFeb 20, 2026
Press enter or click to view image in full size

When deciding which Gang of Four design pattern to use, it is important to consider the specific problem you are trying to solve, the design, and the goals you want to achieve. Here is a toolkit to help you determine which pattern design is appropriate for your situation:

  1. Singleton Pattern:
    - Use when there should be only one instance of a class in the entire program.
    - Use when you want a global point of access to an object.
Singleton Pattern

2. Builder Pattern:
- Use when you need to create complex objects step by step, allowing different configurations.
- Use when you want to separate the construction of an object from its representation.
- Use when you want to create different representations of the same object.

Press enter or click to view image in full size
Builder Pattern

3. Factory Method Pattern:
- Use when you want to delegate object creation to subclasses.
- Use when you want to provide a way for clients to create objects without specifying their concrete classes.
- Use when you want to encapsulate object creation logic.

Press enter or click to view image in full size
Factory Method Pattern

4. Abstract Factory Pattern:
- Use when you want to provide a way to create families of related or dependent objects without specifying their concrete classes.
- Use when you want to provide a single interface for creating multiple objects.

Press enter or click to view image in full size
Abstract Factory Pattern

5. Prototype Pattern:
- Use when creating new objects is costly or complex.
- Use when you want to avoid coupling between the client code and the classes being instantiated.
- Use when you want to create new objects by cloning existing ones.

Prototype Pattern

6. Adapter Pattern:
- Use when you want to convert the interface of a class into another interface that expects clients.
- Use when you want to make incompatible classes work together.
- Use when you want to reuse existing useful classes that do not have the required interface.

Press enter or click to view image in full size
Adapter Pattern

7. Proxy Pattern:
- Use when you want to control access to an object.
- Use when you want to add functionality to an object without modifying its original code.
- Use when you want to lazily load and instantiate objects.

Proxy Pattern

8. Decorator Pattern:
- Use when you want to add responsibilities to an object dynamically.
- Use when subclassing to extend functionality is impractical or leads to a class explosion.
- Use when you want to provide additional behaviors to individual objects at runtime.

Decorator Pattern

9. Composite Pattern:
- Use when you want to represent a part-whole hierarchy of objects as a tree structure.
- Use when you want clients to treat individual objects and compositions of objects uniformly.

Composite Pattern

Get Pawan Gupta’s stories in your inbox

Join Medium for free to get updates from this writer.

10. Observer Pattern:
- Use when you want to establish a one-to-many dependency between objects.
- Use when changes in one object require other objects be notified and updated automatically.
- Use when the decoupling of objects is desired.

Press enter or click to view image in full size
Observer Pattern

11. Bridge Pattern:
- Use when you want to separate the abstraction and the implementation so that they can vary independently.
- Use when you want to avoid a permanent binding between an and its abstraction implementation.
- Use when changes in the abstraction or implementation should not affect each other.

Press enter or click to view image in full size
Bridge Pattern

12. Facade Pattern:
- Use when you want to provide a simple interface to a complex system.
- Use when you want to hide the complexities of individual subsystems and provide a unified interface.

Facade Pattern

13. Flyweight Pattern:
- Use when you want to share objects to support large numbers of fine-grained objects efficiently.
- Use when object creation and initialization overhead is significant- Use.
when most of the object state can be made extrinsic (i.e., shared).

Flyweight Pattern

14. Chain of Responsibility Pattern:
- Use when you want to chain objects together to process a request.
- Use when the request should be handled by one or more objects dynamically.
Use when you want to avoid coupling the sender and receiver explicitly.

Press enter or click to view image in full size
Chain of Responsibility Pattern

15. Command Pattern:
- Use when you want to encapsulate a request as an object, thereby allowing parameterization of clients with different requests.
- Use when you want to support operations such as undo and redo.
- Use when you want to allow objects to be queued, logged, or processed asynchronously.

Command Pattern

16. Interpreter Pattern:
- Use when you want to define a representation for grammar along with an interpreter that uses the representation to interpret sentences in the language.
- Use when the grammar is simple and can be handled adequately by a set of classes.
- Use when efficiency is not a primary concern.

Interpreter Pattern

17. Iterator Pattern:
- Use when you want to provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- Use when you want to support multiple traversals of an aggregate object concurrently.
- Use when you want to provide a uniform interface for iterating over different types of collections.

Press enter or click to view image in full size
Iterator Pattern

18. Mediator Pattern:
- Use when you want to define an object that encapsulates and controls the interaction between a group of objects.
- Use when direct communication between objects is undesirable or unmanageable.
- Use when you want to centralize complex communication and reduce coupling.

Press enter or click to view image in full size
Mediator Pattern

19. Memento Pattern:
- Use when you need to capture and externalize an object’s internal state without violating encapsulation.
- Use when you want to restore an object to a previous state.
- Use when you want to save and restore the state of an object externally.

Press enter or click to view image in full size
Memento Pattern

Each pattern serves a specific purpose and addresses different design concerns. By having a toolkit of design patterns, you can choose the most appropriate pattern(s) based on your specific requirements and constraints.

--

--

Pawan Gupta
Pawan Gupta

Written by Pawan Gupta

#TechEnthusiast #Programmer #Blogger