Design Patterns help in building maintainable and reusable code.
Here are the 23 Design Patterns explained by the Gang of Four in their book “Design Patterns – Elements of Reusable Object-Oriented Software”
All the posts have been created by referring to the original book and they follow the below format:
- A Use Case which the design pattern solves
- Explanation of the Design Pattern with code
- What the Gang of Four say about the pattern
- Link to Github URL with the entire code describing the pattern.
These articles are also available as an eBook here (gumroad) or here (kindle) and as a paperback here:
Deals with how to create objects.
Singleton – Create a single instance of an object.
Prototype – Use an existing object by cloning it.
Factory Method – Delegate creation of an object to another object.
Abstract Factory – Delegate creation of a group of related objects to another object.
Builder – Delegate creation of a complex object to another object.
Deals with how to structure objects.
Adapter – Make two incompatible interfaces work together.
Bridge – Separate abstraction and implementation.
Composite – Treat part-whole hierarchy the same way.
Decorator – Add responsibilities to an object dynamically.
Facade – Provide a single interface for a group of related operations.
Flyweight – Reuse objects than creating new ones.
Proxy – Protect access to an object.
Deals with how to communicate between objects.
Chain of Responsibility – Allow different objects to carry out a responsibility.
Command – Encapsulate requests as separate objects.
Mediator – Act as a broker for communication between objects.
Template – Provide basic template of an algorithm to implement.
Strategy – Encapsulate different algorithms using separate objects which can be chosen at run time.
State – Encapsulate state specific behavior in a separate object.
Observer – Intimate group of objects when a change occurs.
Memento – Allow to revert an object’s state.
Iterator – Provide a generic way to iterate through collection of objects.
Interpreter – Represent a grammar using an object.
Visitor – Add new responsibilities to an object without changing its existing behavior.
The code samples for all the above patterns structured under respective folders are present here :
Leave a Reply