Design Patterns
Explore the Gang of Four design patterns. Each pattern includes detailed explanations, interactive code examples, and real-world use cases.
Creational Patterns
Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.
Singleton
Ensures a class has only one instance and provides a global point of access to it.
Factory Method
Defines an interface for creating objects, but lets subclasses decide which class to instantiate.
Builder
Separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
Abstract Factory
Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Prototype
Specifies the kinds of objects to create using a prototypal instance, and creates new objects by copying this prototype.
Structural Patterns
Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
Decorator
Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Adapter
Converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Composite
Composes objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Facade
Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Proxy
Provides a surrogate or placeholder for another object to control access to it.
Behavioral Patterns
Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects.
Observer
Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Strategy
Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Command
Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
State
Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.