A collection of design patterns and idioms in Python
Creational, Structural, and Behavioral patterns with implementations.
Python Patterns — a collection of design patterns and idioms in Python. Includes Creational, Structural, and Behavioral patterns with ready-to-use implementations.
| Pattern | Description |
|---|---|
| Abstract Factory | Use a generic function with specific factories |
| Builder | Instead of using multiple constructors, builder receives parameters and returns constructed objects |
| Factory Method | Delegate a specialized function/method to create instances |
| Prototype | Use a factory and clones of a prototype for new instances (if instantiation is expensive) |
| Singleton | Ensures that the class has only one instance, and provides a global access point to it |
| Pattern | Description |
|---|---|
| Adapter | Converts the interface of one class to the interface of another that clients expect |
| Bridge | A client-provider middleman to soften interface changes |
| Composite | Lets clients treat individual objects and compositions uniformly |
| Decorator | Wrap functionality with other functionality in order to affect outputs |
| Facade | Use one class as an API to a number of others |
| Flyweight | Transparently reuse existing instances of objects with similar/identical state |
| Proxy | An object funnels operations to something else |
| Pattern | Description |
|---|---|
| Blackboard | Architectural model, assemble different sub-system knowledge to build a solution |
| Chain Of Responsibility | Apply a chain of successive handlers to try and process the data |
| Command | Bundle a command and arguments to call later |
| Interpreter | A behavioral design pattern that solves a frequently encountered but subject to change problem |
| Iterator | Traverse a container and access the container's elements |
| Mediator | An object that knows how to connect other objects and act as a proxy |
| Memento | Generate an opaque token that can be used to go back to a previous state |
| Observer | Provide a callback for notification of events/changes to data |
| State | Logic is organized into a discrete number of potential states and the next state that can be transitioned to |
| Strategy | Selectable operations over the same data |
| Template Method | Defines the basis of the algorithm and allows subclasses to override some steps |
| Visitor | Invoke a callback for all items of a collection |
By using this software, you agree to the full disclaimer terms.
Software provided "AS IS" without warranty. You assume all risks.
Full legal disclaimer: See DISCLAIMER.md
License: BSD 3-Clause License