A complete implementation of all 24 Gang of Four (GoF) design patterns in C# (.NET 6). Every pattern includes working code, two UML diagrams (generic pattern diagram + class diagram), and a README explaining the concept and each class.
- .NET 6 SDK or later
Each pattern is a standalone console application. To run any pattern:
cd <Category>/<PatternName>
dotnet runExamples:
cd BehaviouralPatterns/ObserverPattern
dotnet run
cd CreationalPatterns/SingletonPattern
dotnet run
cd StructuralPatterns/ProxyPattern
dotnet runTo build all patterns in a category at once:
cd BehaviouralPatterns
dotnet build BehaviouralPatterns.slnConcerned with how objects are created.
| Pattern | Description |
|---|---|
| Singleton | Ensures a class has only one instance and provides a global access point |
| Factory Method | Defines an interface for creating an object, but lets subclasses decide which class to instantiate |
| Abstract Factory | Creates families of related objects without specifying their concrete classes |
| Builder | Constructs complex objects step by step, separating construction from representation |
| Prototype | Creates new objects by copying an existing object |
Concerned with how classes and objects are composed to form larger structures.
| Pattern | Description |
|---|---|
| Adapter | Makes incompatible interfaces work together by wrapping one in the other |
| Bridge | Splits a class into two independent hierarchies — abstraction and implementation |
| Composite | Composes objects into tree structures so individual objects and composites are treated uniformly |
| Decorator | Attaches additional responsibilities to an object dynamically |
| Facade | Provides a simplified interface to a complex subsystem |
| Flyweight | Shares common state across many fine-grained objects to reduce memory usage |
| Proxy | Provides a surrogate that controls access to another object |
Concerned with communication and responsibility between objects.
| Pattern | Description |
|---|---|
| Chain of Responsibility | Passes a request along a chain of handlers until one handles it |
| Command | Encapsulates a request as an object, enabling undo, queuing, and logging |
| Interpreter | Defines a grammar and an interpreter to evaluate sentences in that language |
| Iterator | Provides a way to sequentially access elements of a collection without exposing its structure |
| Mediator | Reduces dependencies between objects by routing communication through a central mediator |
| Memento | Captures and restores an object's internal state without violating encapsulation |
| Observer | Notifies a list of dependents automatically when an object's state changes |
| State | Allows an object to change its behaviour when its internal state changes |
| Strategy | Defines a family of algorithms and makes them interchangeable at runtime |
| Template Method | Defines the skeleton of an algorithm in a base class, deferring some steps to subclasses |
| Visitor | Lets you add new operations to a class hierarchy without modifying those classes |
Fork the repository and open a pull request with your changes.
This repository is licensed under the MIT License. You can view the license here.