IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Microservices-design-patterns | Factory-vs-Abstract-Factory-Pattern | |
Design Patterns |
Design patterns are recurring solutions to common problems in software architecture.
One of the most cited definitions comes from Christopher Alexander:
“Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.”
Interestingly, Alexander was referring to architecture—buildings and structures. The Gang of Four adapted this concept to software development.
The Gang of Four (GoF) refers to the authors of the influential book Design Patterns: Elements of Reusable Object-Oriented Software—Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Originally published in 1994, the book remains highly relevant today.
The GoF cataloged 23 design patterns, grouped into three main categories:
| Creational Patterns | |
|---|---|
| Abstract Factory | Creates an instance of several families of classes |
| Builder | Separates object construction from its representation |
| Factory Method | Creates an instance of several derived classes |
| Prototype | A fully initialized instance to be copied or cloned |
| Singleton | A class of which only a single instance can exist |
Mnemonic Phrase: A Big Friendly Panda Sleeps
| Structural Patterns | |
|---|---|
| Adapter | Match interfaces of different classes |
| Bridge | Separates an object’s interface from its implementation |
| Composite | A tree structure of simple and composite objects |
| Decorator | Add responsibilities to objects dynamically |
| Facade | A single class that represents an entire subsystem |
| Flyweight | A fine-grained instance used for efficient sharing |
| Proxy | An object representing another object |
Mnemonic Phrase: All Brave Cats Dance For Fancy Parties
| Behavioural Patterns | |
|---|---|
| Chain of Resp. | A way of passing a request between a chain of objects |
| Command | Encapsulate a command request as an object |
| Interpreter | A way to include language elements in a program |
| Iterator | Sequentially access the elements of a collection |
| Mediator | Defines simplified communication between classes |
| Memento | Capture and restore an object's internal state |
| Observer | A way of notifying change to a number of classes |
| State | Alter an object's behaviour when its state changes |
| Strategy | Encapsulates an algorithm inside a class |
| Template Method | Defer the exact steps of an algorithm to a subclass |
| Visitor | Defines a new operation to a class without change |
Mnemonic Phrase: Calm Cats Interpret Ideas, Making Memories Of Strong Strategic Thinking Ventures
Creational patterns provide mechanisms to instantiate single objects or groups of related objects. There are five key patterns:
Structural patterns define relationships between classes or objects to form larger structures.
Behavioral patterns define communication strategies between objects and classes.
| Microservices-design-patterns | Factory-vs-Abstract-Factory-Pattern | |