
“Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.”
In software terms, a design pattern is a language-independent reusable solution/template to commonly occurring problems. It’s not a library/framework, not algorithms, not a copy-paste solution and finally not mandatory (knowing when NOT to use them is equally important)
Focus: How objects are created
Creational patterns provide flexibility in what gets created, who creates it, how it’s created, and when. They abstract the instantiation process, making systems independent of how objects are created, composed, and represented.
| Pattern | One-Line Summary | Difficulty | Progress |
|---|---|---|---|
| Singleton | Ensure a class has only one instance | β | β |
| Prototype | Clone objects instead of creating new | β | β |
| Factory Method | Define an interface for creating objects | ββ | β |
| Builder | Construct complex objects step by step | ββ | β |
| Abstract Factory | Create families of related objects | βββ | β |
Focus: How objects are composed and related
Structural patterns provide flexibility in what gets created, who creates it, how it’s created, and when. They abstract the instantiation process, making systems independent of how objects are created, composed, and represented.
| Pattern | One-Line Summary | Difficulty | Progress |
|---|---|---|---|
| Adapter | Convert interface to another interface | β | β |
| Facade | Provide simplified interface to subsystem | β | β |
| Decorator | Add behavior to objects dynamically | ββ | β |
| Composite | Treat objects and compositions uniformly | ββ | β |
| Proxy | Control access to an object | ββ | β |
| Bridge | Decouple abstraction from implementation | βββ | β |
| Flyweight | Share common state to save memory | βββ | β |
Focus: How objects communicate and distribute responsibility
Objects need to collaborate to accomplish tasks. Behavioral patterns define clear communication protocols, making interactions flexible and maintainable.
| Pattern | One-Line Summary | Difficulty | Progress |
|---|---|---|---|
| Iterator | Access collection elements sequentially | β | β |
| Template Method | Define skeleton of algorithm in base class | β | β |
| Chain of Responsibility | Pass requests along a chain of handlers | ββ | β |
| Command | Encapsulate requests as objects | ββ | β |
| Memento | Save and restore object state | ββ | β |
| Observer | Define one-to-many dependency | ββ | π§ |
| Strategy | Define family of interchangeable algorithms | ββ | β |
| Mediator | Reduce coupling between objects | βββ | β |
| State | Change behavior when state changes | βββ | β |
| Visitor | Add operations without modifying classes | βββ | β |
When NOT to use patterns:
The goal is clean, maintainable codeβnot using as many patterns as possible.