This repository contains a .NET 10 solution implementing various design patterns in C#. Each design pattern is implemented in a separate console project within the solution.
Each project folder has its own README.md explaining what problem the pattern solves and when to reach for it.
The repository is organized as follows:
DesignPatterns/
│
├── SingletonPattern/
│ ├── Program.cs
│ └── ...
│
├── FactoryPattern/
│ ├── Program.cs
│ └── ...
│
├── BuilderPattern/
│ ├── Program.cs
│ └── ...
│
├── ...
Each folder represents a design pattern and contains a console project that implements that specific pattern.
- Open a terminal and navigate to the directory of the project you want to run. For example, to run the Singleton pattern:
cd /path/to/DesignPatterns/SingletonPattern- Build the project using the
dotnet buildcommand:
dotnet build- Once built, run the program using the
dotnet runcommand:
dotnet runThis command will build the project if necessary and then execute the application.
If you want to run a specific project instead of all projects in the solution, you can specify the project name after the dotnet run command. For example:
dotnet run --project SingletonPatternThis will run only the SingletonPattern project. Replace SingletonPattern with the name of the project you want to run.
Creational
- Singleton
- Factory Method
- Builder
- Prototype
Structural
- Adapter
- Decorator
- Facade
- Bridge
- Composite
- Proxy
Behavioral
- Observer
- Command
- Strategy
- State
- Chain of Responsibility
- Template Method
- Iterator
Other
- Dependency Injection (not a GoF pattern, but common enough in C# to include)
Each design pattern is implemented in its own project and contains code examples demonstrating its usage.
Every project above shows one pattern in isolation. OrderProcessingExample
shows Builder, Strategy and Observer working together in a single, small
order-processing scenario — see its README
for how they fit together.
dotnet run --project OrderProcessingExampleThe DesignPatterns.Tests project covers all 18 patterns and the combined
example above. Run it with:
dotnet test DesignPatterns.slnCI also runs dotnet format --verify-no-changes to catch style issues, and
publishes a coverage summary to each run's job summary on GitHub Actions.
This project is licensed under the MIT License.