A hands-on collection of Gang of Four design patterns implemented in C# with Exalidraw diagrams and examples.
Perfect for .NET developers preparing for interviews, studying software architecture, or looking for clean, copy-paste-ready pattern implementations.
| Pattern | Description | Code |
|---|---|---|
| Singleton | Ensures a single instance with global access point | singleton_pattern/ |
| Factory Method | Delegates object creation to subclasses | factory_pattern/ |
| Builder | Constructs complex objects step by step with validation | builder_pattern/ |
| Pattern | Description | Code |
|---|---|---|
| Adapter | Makes incompatible interfaces work together | adapter_pattern/ |
| Bridge | Decouples abstraction from implementation to avoid class explosion | bridge_pattern/ |
| Composite | Composes objects into tree structures | composite_pattern/ |
| Decorator | Adds behavior dynamically via wrappers | decorator_pattern/ |
| Façade | Simplifies a complex subsystem behind a single interface | façade_pattern/ |
| Proxy | Controls access to another object (includes Remote Proxy) | proxy_pattern/ |
| Pattern | Description | Code |
|---|---|---|
| Strategy | Swaps algorithms at runtime via composition | strategy_pattern/ |
| Template Method | Defines algorithm skeleton, lets subclasses fill in steps | template_method_pattern/ |
| Observer | Notifies multiple objects when state changes | observer_pattern/ |
| Command | Encapsulates requests as objects (supports undo/redo) | command_pattern/ |
| State | Alters behavior based on internal state changes | state_pattern/ |
| Iterator | Traverses collections without exposing internals | iterator_pattern/ |
| Pattern | Description | Code |
|---|---|---|
| Repository | Abstracts data access behind a clean interface | repository_pattern/ |
git clone https://github.com/MarioCodes/csharp-design-patterns.git
cd csharp-design-patternsOpen any pattern folder in Visual Studio or VS Code and run the examples.
These are the core SOLID and OOP principles applied throughout the examples:
- Identify the aspects of your application that vary and separate them from what stays the same
- Program to an interface, not an implementation
- Favor composition over inheritance -
has-amay be better thanis-a - Strive for loosely coupled designs between objects that interact
- Classes should be open for extension, but closed for modification
Contributions are welcome! Here are some ideas:
- Add missing GoF patterns
- Improve or add new Excalidraw diagrams
- Translate descriptions to other languages
Just fork, make your changes, and submit a PR.
This project is licensed under the MIT License — see the LICENSE file for details.
If this repo helped you understand design patterns or prepare for an interview, consider giving it a star