C# Design Patterns Repository

This repository contains examples of various design patterns implemented in C#. Design patterns are reusable solutions to common problems encountered in software design and are categorized into three groups: Creational, Structural, and Behavioral.

Below, you'll find examples of each design pattern along with a brief explanation of its purpose:

Structural Patterns

Pattern Explanation Short Description Example Code
Adapter Explanation Convert the interface of a class into another interface clients expect. Example Code
Bridge Explanation Decouple an abstraction from its implementation so that the two can vary independently. Example Code
Composite Explanation Compose objects into tree structures to represent part-whole hierarchies. Example Code
Decorator Explanation Attach additional responsibilities to an object dynamically. Example Code
Facade Explanation Provide a unified interface to a set of interfaces in a subsystem. Example Code
Flyweight Explanation Use sharing to support large numbers of fine-grained objects efficiently. Example Code
Proxy Explanation Provide a surrogate or placeholder for another object to control access to it. Example Code

Behavioral Patterns

Pattern Explanation Short Description Example Code
Chain of Responsibility Explanation Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Example Code
Command Explanation Encapsulate a request as an object, thereby parameterizing clients with queues, requests, and operations. Example Code
Interpreter Explanation Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. Example Code
Iterator Explanation Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Example Code
Mediator Explanation Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly and allows their interaction to vary independently. Example Code
Memento Explanation Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later. Example Code
Observer Explanation Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Example Code
State Explanation Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. Example Code
Strategy Explanation Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Example Code
Template Method Explanation Define the skeleton of an algorithm in the superclass but let subclasses override specific steps of the algorithm without changing its structure. Example Code
Visitor Explanation Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. Example Code

Creational Patterns

Pattern Explanation Short Description Example Code
Abstract Factory Explanation Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Example Code
Builder Explanation Separate the construction of a complex object from its representation so that the same construction process can create different representations. Example Code
Factory Method Explanation Define an interface for creating an object, but let subclasses alter the type of objects that will be created. Example Code
Prototype Explanation Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Example Code
Singleton Explanation Ensure a class has only one instance and provide a global point of access to it. Example Code

License

This project is licensed under the MIT License.