/
Tech-study-notes

Design Patterns

“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)


Creational Patterns

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.

PatternOne-Line SummaryDifficultyProgress
SingletonEnsure a class has only one instanceβ­βœ…
PrototypeClone objects instead of creating newβ­βœ…
Factory MethodDefine an interface for creating objectsβ­β­βœ…
BuilderConstruct complex objects step by step⭐⭐❌
Abstract FactoryCreate families of related objects⭐⭐⭐❌

Structural Patterns

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.

PatternOne-Line SummaryDifficultyProgress
AdapterConvert interface to another interfaceβ­βœ…
FacadeProvide simplified interface to subsystemβ­βœ…
DecoratorAdd behavior to objects dynamicallyβ­β­βœ…
CompositeTreat objects and compositions uniformly⭐⭐❌
ProxyControl access to an object⭐⭐❌
BridgeDecouple abstraction from implementation⭐⭐⭐❌
FlyweightShare common state to save memory⭐⭐⭐❌

Behavioral Patterns

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.

PatternOne-Line SummaryDifficultyProgress
IteratorAccess collection elements sequentiallyβ­βœ…
Template MethodDefine skeleton of algorithm in base class⭐❌
Chain of ResponsibilityPass requests along a chain of handlers⭐⭐❌
CommandEncapsulate requests as objects⭐⭐❌
MementoSave and restore object state⭐⭐❌
ObserverDefine one-to-many dependency⭐⭐🚧
StrategyDefine family of interchangeable algorithms⭐⭐❌
MediatorReduce coupling between objects⭐⭐⭐❌
StateChange behavior when state changes⭐⭐⭐❌
VisitorAdd operations without modifying classes⭐⭐⭐❌

Why Use Design Patterns?

Benefits

Warning Signs of Pattern Abuse

When NOT to use patterns:

The goal is clean, maintainable codeβ€”not using as many patterns as possible.


Important Notes