/

Tech-study-notes 0.2.0

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 SummaryDifficulty
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 SummaryDifficulty
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 SummaryDifficulty
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


Sources (images and content): https://refactoring.guru/design-patterns/

Useful resource: https://codesignal.com/learn/paths/mastering-design-patterns-with-java