Gang of Four Design Patterns in .NET

22 Aug 2022
7 min read  

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.

  1. 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:

    1. 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

    2. 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

    3. Builder: Separates an object construction from its representation

    4. Prototype: Create a duplicate object or clone of the object

    5. Singleton: Ensures that a class can have only one instance

  2. 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:

    1. Adapter: Match interfaces of different classes

    2. Bridge: Separates an object’s abstraction from its implementation

    3. 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

    4. Façade: A single class that represents an entire complex system

    5. Flyweight: Minimize memory usage by sharing as much data as possible with similar objects

    6. 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.

  3. Behavioral Design Patterns

    These patterns deal with the process of communication, managing relationships, and responsibilities between objects. There are as follows:

    1. Chain of Responsibility: Passes a request among a list or chain of objects.

    2. Command: Wraps a request under an object as a command and passed it to the invoker object.

    3. Interpreter: Implements an expression interface to interpret a particular context.

    4. Iterator: Provides a way to access the elements of a collection object in a sequential manner without knowing its underlying structure.

    5. Mediator: Allows multiple objects to communicate with each other without knowing each other’s structure.

    6. 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.

    7. 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.

    8. State: Alters the behavior of an object when its internal state changes.

    9. 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.

    10. Visitor: Creates and performs new operations onto a set of objects without changing the object structure or classes.

    11. Template Method: Defines the basic steps of an algorithm and allows the implementation of the individual steps to be changed.

Read More Articles Related to Design Pattern
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.
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Learn to Crack Your Technical Interview

Accept cookies & close this