Welcome to Py-DesignPattern, a hands-on exploration of software design patterns using Python. This repository serves as a personal review space for mastering design patterns while keeping the examples relevant through the lens of a coffee shop context. Every pattern will be demonstrated using real-world coffee shop scenarios to make learning more intuitive and practical.
Main resource: Refactoring Guru
If you're a Python developer looking to strengthen your understanding of design patterns, this repository is for you. Each pattern includes a concise explanation and an implementation in Python.
Creational patterns provide object creation mechanisms that increase flexibility and reuse of existing code.
- Singleton - Ensures a class has only one instance and provides a global access point.
- Factory - Defines an interface for creating objects but lets subclasses alter the type of objects that will be created.
- Abstract Factory - Provides an interface for creating families of related or dependent objects.
- Prototype - Creates objects based on a prototype instance, avoiding costly creation.
- Builder - Constructs complex objects step by step, separating construction from representation.
Structural patterns explain how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient.
- Adapter - Allows incompatible interfaces to work together.
- Bridge - Decouples abstraction from implementation.
- Composite - Treats individual objects and compositions of objects uniformly.
- Decorator - Dynamically adds behavior to objects.
Behavioral patterns take care of effective communication and the assignment of responsibilities between objects.
- Observer - Defines a dependency between objects so that when one changes, its dependents are notified.
- Strategy - Defines a family of algorithms and lets them be interchangeable.
- Command - Encapsulates requests as objects, allowing undoable operations.
- State - Allows an object to change behavior when its internal state changes.
Contributions are welcome! Feel free to fork this repository, submit issues, or create pull requests to add or improve pattern implementations.
Happy coding! ☕🚀