Skip to content

amulyavarshney/Design-Patterns-in-CSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns in C#

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.

Prerequisites

How to Run

Each pattern is a standalone console application. To run any pattern:

cd <Category>/<PatternName>
dotnet run

Examples:

cd BehaviouralPatterns/ObserverPattern
dotnet run

cd CreationalPatterns/SingletonPattern
dotnet run

cd StructuralPatterns/ProxyPattern
dotnet run

To build all patterns in a category at once:

cd BehaviouralPatterns
dotnet build BehaviouralPatterns.sln

Creational Patterns

Concerned 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

Structural Patterns

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

Behavioural Patterns

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

Contributing

Fork the repository and open a pull request with your changes.

License

This repository is licensed under the MIT License. You can view the license here.

About

This repository showcases implementation of various design patterns in CSharp including creational, structural & behavioral patterns in a way that makes it easy for developers to understand the concepts and patterns. It includes a brief description of each design pattern, along with example code and explanation.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages