Python Design Patterns - Condensed Cheatsheet
Creational Patterns
Singleton: Ensure a class has only one instance. Used for config, DB connections.
Factory Method: Define an interface for creating an object, but let subclasses decide which class to instantiate.
Abstract Factory: Provide an interface to create families of related or dependent objects.
Builder: Separate the construction of a complex object from its representation.
Prototype: Create new objects by copying an existing object (clone).
Structural Patterns
Adapter: Convert the interface of a class into another interface clients expect.
Bridge: Separate an objects interface from its implementation.
Composite: Compose objects into tree structures to represent part-whole hierarchies.
Decorator: Attach new responsibilities to objects dynamically.
Facade: Provide a unified interface to a set of interfaces in a subsystem.
Flyweight: Use sharing to support large numbers of fine-grained objects efficiently.
Proxy: Provide a surrogate or placeholder for another object.
Behavioral Patterns
Chain of Responsibility: Pass request along a chain of handlers.
Command: Encapsulate a request as an object.
Interpreter: Given a language, define a grammar representation and an interpreter.
Iterator: Provide a way to access elements of an aggregate object sequentially.
Mediator: Define an object that encapsulates how a set of objects interact.
Memento: Capture and restore an objects internal state.
Observer: Define a one-to-many dependency between objects.
State: Allow an object to alter its behavior when its internal state changes.
Strategy: Define a family of algorithms and make them interchangeable.
Template Method: Define the skeleton of an algorithm in a method.
Visitor: Represent an operation to be performed on elements of an object structure.