Creational Pattern | Structural Pattern | Behavioral Pattern | |
---|---|---|---|
Description | Provides object creation mechanisms, which increase flexibility and reuse of existing code. | Explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. | Concerned with algorithms and the assignment of responsibilities between objects. |
ID | Name | Description | Visualization |
---|---|---|---|
1 | Factory Method | Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. | |
2 | Abstract Factory | Lets you produce families of related objects without specifying their concrete classes. | |
3 | Builder | Lets you construct complex objects step by step. The pattern allows you to produce different types and representations of an object using the same construction code. | |
4 | Singleton | Lets you ensure that a class has only one instance while providing a global access point to this instance. | |
5 | Prototype | Lets you copy existing objects without making your code dependent on their classes. |
ID | Name | Description | Visualization |
---|---|---|---|
1 | Adapter | Allows objects with incompatible interfaces to collaborate. | |
2 | Bridge | Lets you split a large class or a set of closely related classes into two separate hierarchies - abstraction and implementation - which can be developed independently of each other. | |
3 | Composite | Lets you compose objects into tree structures and then work with these structures as if they were individual objects. | |
4 | Decorator | Lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. | |
5 | Facade | Provides a simplified interface to a library, a framework, or any other complex set of classes. | |
6 | Flyweight | Lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object. | |
7 | Proxy | Lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object. |
ID | Name | Description | Visualization |
---|---|---|---|
1 | Chain of Responsibility | Lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain. | |
2 | Command | Turns a request into a standalone object that contains all info about the request. This transformation lets you pass requests as method arguments, delay or queue a request's execution, and support undoable operations. | |
3 | Iterator | Lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.). | |
4 | Mediator | Lets you reduce chaotic dependencies between objects. The pattern restricts direct communication between the objects and forces them to collaborate only via a mediator object. | |
5 | Memento | Lets you save and restore previous state of an object without revealing the details of its implementation. | |
6 | Observer | Lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they're observing. | |
7 | State | Lets an object alter its behavior when its internal state changes. It appears as if the object changed its class. | |
8 | Strategy | Lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable. | |
9 | Template Method | Defines a skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. | |
10 | Visitor | Lets you separate algorithms from the objects on which they operate. |
This project lists UML diagrams of the "Design Pattern Examples in Python". When you click on a diagram image, the diagram will be opened in Diagram Map. If you want to know about Diagram Map, see this post.
1. Abstract Factory | 2. Builder | 3. Factory Method |
Python Code |
Python Code |
Python Code |
4. Prototype | 5. Singleton | |
Python Code |
Python Code |
1. Adapter | 2. Bridge | 3. Composite |
Python Code |
Python Code |
Python Code |
Decorator | Facade | Flyweight |
Python Code |
Python Code |
Python Code |
Proxy | ||
Python Code |
1. Chain of Responsibility | 2. Command | 3. Interpreter |
Python Code |
Python Code |
Python Code |
4. Iterator | 5. Mediator | 6. Memento |
Python Code |
Python Code |
Python Code |
7. Observer | 8. State | 9. Strategy |
Python Code |
Python Code |
Python Code |
10. Template Method | 11. Visitor | |
Python Code |
Python Code |
- Gamma, E. et al. Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1994
- Hiroshi Yuki. Learning Design Patterns in Java [In Japanese Language], Softbank publishing, 2004
Diagram Map file (DiagramMap.html) includes the following libraries:
- D3 library is copyrighted by Mike Bostock and is released under the BSD license.
- Popper library is copyrighted by Federico Zivolo and is released under the MIT license.
- Tippy library is copyrighted by atomiks and is released under the MIT license.