This repo plans to serve as a cheatsheet or a notebook with practical examples that explain the use of design patterns in software development. Some of those examples are created by myself, others by Dmitri Nesteruk in his [Design Patterns in C# and .NET course](Design Patterns in C# and .NET )
I'm using C# console applications with .NET 8.0
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. It represents best practices evolved over time by experienced software developers. Design patterns can speed up the development process by providing tested, proven development paradigms. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for developers who are familiar with the patterns.
Design patterns can be categorized into three main types:
-
Creational Patterns: These patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include the Singleton, Factory Method, and Abstract Factory patterns.
-
Structural Patterns: These patterns focus on the composition of classes or objects to form larger structures. Examples include the Adapter, Composite, and Decorator patterns.
-
Behavioral Patterns: These patterns are concerned with the interaction and responsibility of objects. They define patterns of communication between classes and objects. Examples include the Observer, Strategy, and Command patterns.
There is an example in the Creational project
Some objects are simple and can be created in a single constructor call. This pattern makes easy and productive the construction of any object, specially when you need a lot of arguments to create that object.
There are several ways to implement this pattern. You can use:
- Basic builder implementation
- Fluent builder. e. g.: when you create a request using Flurl
var request = _baseUrl.AppendPathSegment("/example).WithHeader("x-api-version", "1.0").GetStringAsync();
. You can see an example with recursive generics at Creational/FluentBuilderWithGenerics.cs - Stepwise builder
- Functional builder
- Faceted Builder