Gang of Four (GOF) Design Patterns in .Net
In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book (Design Patterns: Elements of Reusable Object-Oriented Software) for explaining the concept of Design Pattern in Software development. These four authors are collectively known as Gang of Four (GOF).
GOF Design Patterns
The 23 Design 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 creation 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 : Create instances of derived classes
Abstract Factory : Create instances of several classes belonging to different families
Builder : Separates an object construction from its representation
Prototype : Create a duplicate object or clone of the object
Singleton : Ensures that a class can has 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. There are as follows:
Adapter : Match interfaces of different classes
Bridge : Separates an object’s abstraction from its implementation
Composite : A tree structure of simple and composite objects
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 : Provides a surrogate object, which references to other object
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 to invoker object.
Interpreter: This pattern involves implementing an expression interface which tells to interpret a particular context.
Iterator: It provides a way to access the elements of a collection object in sequential manner without knowing its underlying structure.
Mediator: It allows multiple objects to communicate with each other’s without knowing each other’s structure.
Memento: It used to 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: It used when there is one to many relationship between objects such as if one object is modified.
State: It used when there is one to many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically.
Strategy: It 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: It used to create and perform new operations onto a set of objects without changing the object structure or classes.
Template Method: It used to define the basic steps of an algorithm and allow the implementation of the individual steps to be changed.