9 OOP Design Patterns You Must Know
These patterns can be divided into 3 categories:
A - Creational Patterns Deal with object creation mechanism to decouple the client code from concrete classes.
- Factory Pattern: Centralizes object creation logic and returns different subclasses based on input
- Singleton Pattern: Ensures only one instance of a class exists and provides global access to it.
- Builder Pattern: Constructs complex objects step-by-step, allowing optional configuration.
B - Structural Patterns Help compose classes and objects into larger structures.
- Adapter Pattern: Allows incompatible interfaces to work together by translating one interface into another.
- Decorator Pattern: Adds new behavior to objects dynamically without altering their original structure.
- Proxy Pattern: Acts as a placeholder for accessing another object.
C - Behavioral Patterns Focus on communication and interaction between objects.
- Strategy Pattern: Allows selecting an algorithm or behavior from a family of interchangeable strategies at runtime.
- Observer Pattern: Enables a one-to-many dependency so that when one object changes state, all its dependents are notified.
- Command Pattern: An object encapsulates all information needed to perform an action or trigger an event.