Gang of Four Design Patterns in .NET
The four authors Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides are collectively introduced the Gang of Four Design Patterns in Software development. In 1994, they published a book (Design Patterns: Elements of Reusable Object-Oriented Software) for explaining the concept of Design Patterns.
Design patterns provide real solutions to the common software design problems that occur while working with the small or enterprise applications. While working with the object-oriented programming languages, design patterns are generally configured for solving the problems of the object generation and their interaction between each object, rather than the larger-scale problems of the overall software architectures. Design patterns give a generalized solution in the form of templates that may be applied to real-world problems and resolve them effectively.
GoF Design Patterns
The GoF Design Patterns are divided or distributed into three different categories those are creational design patterns used for the creation of the objects, structural design patterns to provide the relationships between objects, and the third pattern is behavioral design patterns to help define how objects will have interacted.
In total, there are total 23 numbers of the Designs patterns are defined by the Gang of Four programmers. These 23 patterns are divided into three groups depending on the nature of the design problem they intend to solve.
Creational Design Patterns
These patterns deal with the process of objects created in such a way that they can be decoupled from their implementing system. This provides more flexibility in deciding which objects need to be created for a given use case/ scenario. There are as follows:
Factory Method: The factory design pattern is used to replace the class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time
Abstract Factory: Create instances of several classes belonging to different families, and the "families" of the different objects created by the factory are determined at run-time itself
Builder: Separates an object construction from its representation
Prototype: Create a duplicate object or clone of the object
Singleton: Ensures that a class can have only one instance
Structural Design Patterns
These patterns deal with the composition of objects structures. The concept of inheritance is used to compose interfaces and define various ways to compose objects for obtaining new functionalities.
This type of design pattern more focuses on how the classes and objects can be composed to form relatively absolute and robust application structures. This pattern is generally used to inherit to compose the interfaces or their implementations.
There are as follows:
Adapter: Match interfaces of different classes
Bridge: Separates an object’s abstraction from its implementation
Composite: The composite pattern is used to create tree structures or the hierarchical, recursive tree structures of the set of related objects where any of the elements of the structure may be accessed and utilized in a specific manner.
Decorator: Add responsibilities to objects dynamically
Façade: A single class that represents an entire complex system
Flyweight: Minimize memory usage by sharing as much data as possible with similar objects
Proxy: The proxy design pattern is used to provide the placeholder object, which is referenced to an underlying object. The proxy type provides a similar public interface as the underlying subject class, by adding the level of indirection by accepting requests from a client object and passing that request to the real subject object as required.
Behavioral Design Patterns
These patterns deal with the process of communication, managing relationships, and responsibilities between objects. There are as follows:
Chain of Responsibility: Passes a request among a list or chain of objects.
Command: Wraps a request under an object as a command and passed it to the invoker object.
Interpreter: Implements an expression interface to interpret a particular context.
Iterator: Provides a way to access the elements of a collection object in a sequential manner without knowing its underlying structure.
Mediator: Allows multiple objects to communicate with each other without knowing each other’s structure.
Memento: Capture the current state of an object and store it in such a manner that it can be restored at a later time without breaking the rules of encapsulation.
Observer: Allows an object (subject) to publish changes to its state and other objects (observer) that depend upon that object are automatically notified of any changes to the subject's state.
State: Alters the behavior of an object when its internal state changes.
Strategy: Allows a client to choose an algorithm from a family of algorithms at run-time and gives it a simple way to access it.
Visitor: Creates and performs new operations onto a set of objects without changing the object structure or classes.
Template Method: Defines the basic steps of an algorithm and allows the implementation of the individual steps to be changed.
What do you think?
A design pattern is a kind of general, reusable solution for the commonly triggered problems while working with the applications. The primary idea is that we can resolve the ultimate issues of certain problems with similar types of solutions. In addition, the solutions using the specific design patterns have been tried & tested over a long period of time effectively. Design patterns generally provide a template as a platform for how to solve a certain problem and can be used in multiple crucial situations. At the same time, it can help us to achieve the best possible design pattern while having the flexibility to achieve the desired results.I hope you will enjoy the GOF design patterns while designing your software. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.