This project provides easy-to-understand code examples of the most important design patterns in Python. The goal is to help developers grasp the core principles behind each pattern through clear, concise, and practical demonstrations.
- Introduction
- Foundation Design Principles
- SOLID
- Creational Patterns
- Structural Patterns
- Behavioral Patterns
- Architectural Design Patterns
- Concurrency and Asynchronous Patterns
- License
Design patterns are proven solutions to common problems in software design. This repository aims to make learning these patterns accessible by providing simple Python examples and explanations.
The foundation of good software design starts with understanding key principles. This section contains examples that illustrate these concepts:
Isolate parts of your code that are likely to change and encapsulate them. Techniques include polymorphism and property-based getters/setters.
See: encapsulate_what_varies.py
Favor composing objects from simpler parts rather than inheriting functionality from base classes.
See: composition_over_inheritance.py
Minimize dependencies between components using abstraction and dependency injection.
Use abstract base classes and protocols to define contracts for your classes, enabling flexible and robust code.
A class should have only one reason to change, meaning it should be responsible for a single part of the program's functionality. This makes code easier to maintain and extend. For example, instead of one class handling both car actions and race results, split responsibilities into separate classes.
Once a software entity is defined and implemented, it should not be changed to add new functionality. Instead, the entity should be extended through inheritance or interfaces to accommodate new requirements and behaviors.
See: open_closed.py
According to the LSP, if a program uses objects of a superclass, then the substitution of these objects with objects of a subclass should not change the correctness and expected behavior of the program.
Coming soon...
Coming soon...
Coming soon...
Coming soon...
Coming soon...
This project is licensed under the GNU General Public License v3.0