Welcome to the Design Patterns Repository! This repository serves as a comprehensive guide and reference for understanding and implementing various software design patterns.
- Introduction
- What are Design Patterns?
- Categories of Design Patterns
- How to Use This Repository
- Contributing
- License
Design patterns are proven solutions to common software design problems. They provide a template for writing code that is reusable, maintainable, and scalable. This repository contains examples and explanations of various design patterns to help developers improve their coding practices.
Design patterns are typical solutions to recurring problems in software design. They are not finished designs but templates that can be adapted to solve specific problems in different contexts.
Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include:
- Factory Method
Exercise Code Basic Example main.py Message Queue message_queue.py Document Exporter document_exporter.py Data Exporter data_exporter.py - Abstract Factory
Exercise Code Basic Example main.py Cloud Provisioning cloud_provisioning.py Data Processing data_processing.py - Builder
Exercise Code Basic Example main.py Query Builder query_builder.py API Request Builder api_request_builder.py Server Config Builder server_configuration_builder.py - Prototype
Exercise Code Basic Example main.py Template BluePrint template_blueprint.py Service Configuration service_configuration.py Lazy Configuration lazy_configuration.py - Singleton
Exercise Code Basic Example main.py Log Bus log_bus.py Connection Pool connection_pool.py Application Bootstrap application_bootstrap.py
Structural patterns focus on the composition of classes and objects. Examples include:
- Adapter
Exercise Code Basic Example main.py Data Processing data_processing.py - Bridge
Exercise Code Basic Example main.py Payment Gateway payment_gateway.py Notification Sender notification_sender.py Database Provider database_provider.py - Composite
Exercise Code Basic Example main.py Math Expression mathematical_expression.py Task Management task_management.py - Decorator
Exercise Code Basic Example main.py Service Decorator service_decorator.py Request Client request_client.py Payment Processor payment_processor.py Logging System logging_system.py - Facade
Exercise Code Basic Example main.py System Deployment system_deployment.py Data Store data_store.py API Gateway api_gateway.py - Flyweight
Exercise Code Basic Example main.py Particle System partical_system.py Cache Manager cache_manager.py - Proxy
Exercise Code Basic Example main.py Fibonacci Calculator fibonacci_calculator.py Dynamic Proxies dynamic_proxies.py Security Proxy security_proxy.py
Behavioral patterns are concerned with communication between objects. Examples include:
- Chain of Responsibility
Exercise Code Basic Example main.py Payment Gateway payment_gateway.py Chain Builder chain_builder.py Request Validator request_validator.py Content Processor content_processor.py - Command
Exercise Code Basic Example main.py Smart Home smart_home.py Scheduler scheduler.py Command Bus command_bus.py Database Transaction database_transaction.py - Iterator
Exercise Code Basic Example main.py Book Shelf book_shelf.py Binary Tree binary_tree.py Log Analyzer log_analyzer.py API Paginated api_paginated.py - Mediator
Exercise Code Basic Example main.py Chat Room chat_room.py Smart Home smart_home.py Service Orchestrator service_orchestrator.py - Memento
Exercise Code Basic Example main.py Text Buffer text_buffer.py Config Manager config_manager.py Transaction Manager transaction_manager.py - Observer
Exercise Code Basic Example main.py Event Bus event_bus.py Domain Event domain_event.py Stock Alert stock_alert.py Service Monitor service_monitor.py - State
Exercise Code Basic Example main.py Order Workflow order_workflow.py Document Workflow document_workflow.py - Strategy
Exercise Code Basic Example main.py Shipping Cost shipping_cost.py Pricing Engine pricing_engine.py - Template Method
Exercise Code Basic Example main.py Data Pipeline data_pipeline.py Order Processor order_processor.py - Visitor
Exercise Code Basic Example main.py Tax Calculator tax_calculator.py Document Export document_export.py AST Calculator ast_calculator.py
- Clone the repository:
git clone https://github.com/duthaho/python-design-patterns.git
- Navigate to the pattern of interest in the directory structure.
- Read the explanation and review the code examples provided.
- Experiment with the code to understand how the pattern works.
Contributions are welcome! If you have improvements or new patterns to add, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Commit your changes and push them to your fork.
- Submit a pull request with a detailed description of your changes.
This repository is licensed under the MIT License. Feel free to use the code and examples in your own projects.
Happy coding!