designpattern.site

Design Patterns

OOP design patterns with interactive diagrams and code examples in TypeScript, Python, Java, and Go.

Design patterns are reusable solutions to commonly occurring problems in software design. Each pattern page includes a class diagram, implementation examples in all four languages, and a discussion of trade-offs.

Creational Patterns

These patterns deal with object creation mechanisms, aiming to create objects in a manner suitable to the situation.

PatternDescription
SingletonEnsure a class has only one instance and provide a global access point
Factory MethodDefine an interface for creating objects, letting subclasses decide which class to instantiate
Abstract FactoryProduce families of related objects without specifying their concrete classes
BuilderConstruct complex objects step by step, separating construction from representation
PrototypeClone existing objects without coupling to their classes

Structural Patterns

These patterns explain how to assemble objects and classes into larger structures while keeping them flexible and efficient.

PatternDescription
AdapterConvert the interface of a class into another interface clients expect
BridgeDecouple an abstraction from its implementation so the two can vary independently
CompositeCompose objects into tree structures to represent part-whole hierarchies
DecoratorAttach additional responsibilities to an object dynamically
FacadeProvide a simplified interface to a complex subsystem
FlyweightUse sharing to support large numbers of fine-grained objects efficiently
ProxyProvide a surrogate or placeholder for another object to control access

Behavioral Patterns

These patterns are concerned with algorithms and the assignment of responsibilities between objects.

PatternDescription
Chain of ResponsibilityPass a request along a chain of handlers until one handles it
CommandEncapsulate a request as an object, enabling undo, queuing, and logging
IteratorAccess elements of a collection sequentially without exposing its representation
MediatorDefine an object that encapsulates how a set of objects interact
MementoCapture and restore an object's internal state without violating encapsulation
ObserverDefine a one-to-many dependency so dependents are notified of state changes
StateAllow an object to alter its behavior when its internal state changes
StrategyDefine a family of algorithms, encapsulate each one, and make them interchangeable
Template MethodDefine the skeleton of an algorithm, letting subclasses override specific steps
VisitorDefine new operations on elements without changing their classes

On this page