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