This repository contains implementations of various Design Patterns in C#. Each design pattern is implemented as a separate module, demonstrating its usage and providing a practical example. The solution is built using .NET 8 and is designed to help developers understand and practice design patterns in a structured way.
Design patterns are reusable solutions to common problems in software design. This repository provides examples of Creational, Structural, and Behavioral design patterns. Each pattern is implemented in its own namespace and includes a RunPattern method to demonstrate its functionality.
The following design patterns are included in this solution:
- Strategy Pattern
- Observer Pattern
- Decorator Pattern
- Factory Method Pattern
- Abstract Factory Pattern
- Singleton Pattern
- Command Pattern
- Adapter Pattern
- Facade Pattern
- Template Method Pattern
- Iterator Pattern
- Composite Pattern
- State Pattern
- Clone the repository
git clone https://github.com/your-repo/design-patterns-csharp.git cd design-patterns-csharp - Open the solution in Visual Studio 2022.
- Build the solution to ensure all dependencies are resolved.
- Run the application. You will be prompted to select a design pattern to execute.
- Enter the number corresponding to the design pattern you want to run, and the program will demonstrate its functionality.
- Demonstrates how to define a family of algorithms, encapsulate each one, and make them interchangeable.
- Example: Solving quadratic equations using different discriminant strategies.
- Implements a subscription mechanism to notify multiple objects about changes in a subject.
- Example: A publisher-subscriber model.
- Dynamically adds behavior to an object without modifying its structure.
- Example: Adding features to a base object at runtime.
- Defines an interface for creating objects but lets subclasses alter the type of objects that will be created.
- Example: Creating different types of products.
- Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
- Example: Pizza ingredient factories for different cities.
- Ensures a class has only one instance and provides a global point of access to it.
- Example: A configuration manager.
- Encapsulates a request as an object, allowing parameterization of clients with different requests.
- Example: Implementing undo/redo functionality.
- Converts the interface of a class into another interface clients expect.
- Example: Adapting legacy code to work with a new system.
- Provides a simplified interface to a larger body of code.
- Example: Simplifying access to a complex subsystem.
- Defines the skeleton of an algorithm in a method, deferring some steps to subclasses.
- Example: Implementing a workflow with customizable steps.
- Provides a way to access elements of a collection sequentially without exposing its underlying representation.
- Example: Iterating over a custom collection.
- Composes objects into tree structures to represent part-whole hierarchies.
- Example: A file system with directories and files.
- Allows an object to alter its behavior when its internal state changes.
- Example: A finite state machine.
Contributions are welcome! If you have additional design patterns or improvements to existing implementations, feel free to submit a pull request.
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push them to your fork.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy coding! 🎉