Skip to content

MarioCodes/csharp-design-patterns-with-diagrams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

159 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Design patterns in C# - Practical examples with diagrams

C# .NET License: MIT PRs Welcome

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.

📋 Patterns Included

Creational Patterns

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/

Structural Patterns

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/

Behavioral Patterns

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/

Other Patterns

Pattern Description Code
Repository Abstracts data access behind a clean interface repository_pattern/

⚡ Quick Start

git clone https://github.com/MarioCodes/csharp-design-patterns.git
cd csharp-design-patterns

Open any pattern folder in Visual Studio or VS Code and run the examples.


🧠 Design Principles

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-a may be better than is-a
  • Strive for loosely coupled designs between objects that interact
  • Classes should be open for extension, but closed for modification

🤝 Contributing

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.


📚 References


📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


⭐ Found This Useful?

If this repo helped you understand design patterns or prepare for an interview, consider giving it a star

About

Gang of four design patterns in C# with Excalidraw diagrams, examples and pattern comparisons. 17 patterns covering Creational, Structural & Behavioral categories. Based on Head First Design Patterns. Perfecto for .NET developers.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages