This repository contains examples of commonly used design patterns implemented in .NET/C#. Each pattern includes sample code and explanations for better understanding.
| Design Pattern | Description | GitHub Example | Medium Article Link |
|---|---|---|---|
| Abstract Factory | Produces families of related objects via interfaces | View on GitHub | Link |
| Builder | Constructs complex objects step by step | View on GitHub | Link |
| Factory | Delegates object creation to subclasses | View on GitHub | Link |
| Singleton | Ensures a class has only one instance | View on GitHub | Link |
| Prototype | Creates new objects by copying an existing object | View on GitHub | Link |
| Facade | Provides a simplified interface to a complex subsystem | View on GitHub | Link |
| Adapter | Allows incompatible interfaces to work together | View on GitHub | Link |
| Bridge | Decouples an abstraction from its implementation | View on GitHub | Link |
| Composite | Composes objects into tree structures to represent part-whole hierarchies | View on GitHub | Link |
| Decorator | Adds additional behavior to objects dynamically | View on GitHub | Link |
| Flyweight | Minimizes memory usage by sharing common data between similar objects | View on GitHub | Link |
| Proxy | Intercepts requests to an object and adds functionality before or after delegation | View on GitHub | Link |
| Strategy | Defines a family of algorithms and makes them interchangeable | View on GitHub | Link |
| Template Method | Defines the skeleton of an algorithm in a method, deferring some steps to subclasses | View on GitHub | Link |
| Observer | Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified | View on GitHub | Link |
| Chain of Responsibility | Passes a request along a chain of handlers until one of them handles it | View on GitHub | Link |
| Command | Converts requests into stand-alone objects, enabling parameterization, queuing, and undo/redo operations | View on GitHub | Link |
| Iterator | Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation | View on GitHub | Link |
| Mediator | Enables loose coupling between objects by centralizing their communication | View on GitHub | Link |
dotnet/DesignPatterns/
├── CreationalDesignPatterns/
│ ├── AbstractFactoryDesignPattern/
│ ├── BuilderDesignPattern/
│ ├── FactoryDesignPattern/
│ ├── SingletonDesignPattern/
│ └── PrototypeDesignPattern/
├── StructuralDesignPatterns/
│ ├── FacadeDesignPattern/
│ ├── AdapterDesignPattern/
│ ├── BridgeDesignPattern/
│ ├── CompositeDesignPattern/
│ ├── DecoratorDesignPattern/
│ ├── FlyweightDesignPattern/
│ └── ProxyDesignPattern/
├── BehavioralDesignPatterns/
│ ├── StrategyDesignPattern/
│ ├── IteratorDesignPattern/
│ ├── ObserverDesignPattern/
│ ├── ChainOfResponsibilityDesignPattern/
│ ├── CommandDesignPattern/
│ ├── TemplateMethodDesignPattern/
│ └── MediatorDesignPattern/
└── DesignPatterns.sln
Feel free to open a pull request or an issue if you want to contribute. All suggestions and feedback are welcome!
MIT License