Skip to content

hsynkmk/Design-Patterns

Repository files navigation

Design Patterns

A collection of design patterns implemented in C# with clean examples and detailed explanations.

📚 Patterns Catalog

Creational Patterns

  1. Singleton Pattern: Ensures a class has only one instance while providing global access. Ideal for configuration managers and logging systems.
  2. Factory Method Pattern: Defers object creation to subclasses while maintaining a common interface. Enables flexible object generation.
  3. Abstract Factory Pattern: Creates families of related objects without specifying concrete classes. Perfect for cross-platform UI toolkits.
  4. Builder Pattern: Constructs complex objects step-by-step. Useful for creating objects with many optional components.
  5. Prototype Pattern: Creates new objects by cloning prototypes. Efficient for expensive object initialization.

Structural Patterns

  1. Adapter Pattern: Bridges incompatible interfaces. Commonly used in legacy system integration.
  2. Decorator Pattern: Adds responsibilities to objects dynamically. Alternative to subclassing for extending functionality.
  3. Facade Pattern: Provides simplified interface to complex subsystems. Reduces subsystem dependencies.
  4. Composite Pattern: Treats individual objects and compositions uniformly. Ideal for tree-structured hierarchies.
  5. Proxy Pattern: Controls access to another object. Used in lazy loading and access control.
  6. Flyweight Pattern: Minimizes memory usage through object sharing. Effective for large quantities of similar objects.
  7. Bridge Pattern: Decouples abstraction from implementation. Enables independent variation of both.

Behavioral Patterns

  1. Memento Pattern: Captures and restores object state. Essential for undo/redo functionality.
  2. State Pattern: Encapsulates state-specific behavior. Manages object behavior changes during runtime.
  3. Iterator Pattern: Provides sequential access to collection elements. Abstracts traversal logic.
  4. Strategy Pattern: Encapsulates interchangeable algorithms. Enables runtime algorithm selection.
  5. Template Method Pattern: Defines algorithm skeleton with customizable steps. Promotes code reuse.
  6. Command Pattern: Encapsulates requests as objects. Enables queuing and undo operations.
  7. Observer Pattern: Implements publish-subscribe mechanism. Maintains consistency between related objects.
  8. Mediator Pattern: Centralizes complex communication between objects. Reduces direct dependencies.
  9. Chain of Responsibility: Passes requests through handler chain. Achieves loose coupling in request processing.
  10. Visitor Pattern: Separates algorithms from object structures. Enables adding new operations without changing classes.
  11. Composite Pattern: (Note: Composite appears in both Structural and Behavioral categories based on usage context)

🛠 Usage

Each pattern includes:

  • Problem statement
  • Pattern solution
  • C# implementation
  • Usage examples
  • Mermaid class diagrams
  • Key benefits and considerations
# Clone repository
git clone https://github.com/hsynkmk/Design-Patterns.git

📖 Prerequisites

  • Basic understanding of object-oriented programming
  • Familiarity with C# syntax
  • Visual Studio or VS Code (recommended)

🤝 Contributing Contributions welcome! Please:

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a pull request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published