Design Pattern

What is a Design Pattern?

Is a proven solution to a common problem

Similar to architecture patterns, design patterns offer guidelines and best practices at a more granular level within the app. They help make the code testable, reusable, and readable.

Most used design patterns

  1. Singleton Pattern - used when only one instance of a class is needed throughout the application.
  2. Factory - used when creating objects is complex and requires encapsulation of object creation logic.
  3. Observer Pattern- used for event-driven systems where objects need to be notified of changes in other objects.
  4. Delegate Pattern - used to allow objects to communicate and pass data between each other.
  5. Adapter - used to adapt one interface to another, especially when integrating with third-party libraries or systems.
  6. Facade - used to provide a simplified interface to a complex system or library.
  7. Command - used to encapsulate a request as an object, allowing it to be queued or logged.
  8. Iterator - used to provide a way to access the elements of a collection without exposing its underlying implementation.
  9. Strategy - used to encapsulate algorithms and make them interchangeable.
  10. Decorator - used to dynamically add behavior to objects at runtime.
  11. Template Method - used to define the skeleton of an algorithm and allow subclasses to implement specific steps.
  12. Composite - used to represent objects as a tree structure, allowing them to be treated as individual objects or groups.
  13. State - used to encapsulate the behavior of an object based on its internal state.
  14. Proxy - used to provide a placeholder for another object to control access, especially for expensive or remote resources.
  15. Builder - used to separate the construction of a complex object from its representation, allowing different representations to be created.
  16. Chain of Responsibility - used to allow multiple objects to handle a request, each object trying to handle it before passing it on to the next object.
  17. Flyweight - used to minimize memory usage by sharing common parts of objects between multiple instances.
  18. Interpreter - used to interpret a language or grammar by defining a representation for its grammar.
  19. Memento - used to capture and restore an object's internal state without violating encapsulation.

References