May 23, 2024

Gang of Four (GOF) Design Patterns

In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book named Elements of Reusable Object-Oriented Software for explaining the concept of design pattern in Software development. These four authors are communally known as Gang of Four (GOF). Gang of Four (GoF) design patterns is generally considered the foundation for all other patterns. GoF programmers define 23 Design Pattern and are categorized into 3 groups.

  1. Creational Patterns: deal mainly with creation of Classes & Objects.
  2. Structural Patterns: deal with Class & Object Composition.
  3. Behavioral Patterns: deal with Class & Object communication.

Creational Design Patterns
These patterns deal with the creation of objects & classes in such a way that they can be decoupled from their implementing system. It provides more flexibility in deciding which objects need to be created for a given use case. There are as follows:

  1. Factory Method: Create instances of derived classes
  2. Abstract Factory: Create instances of several classes belonging to different families
  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 has only one instance

Structural Design Patterns
These patterns deal with the composition of Class & Object 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:

  1. Adapter: Match interfaces of different classes
  2. Bridge: Separates an object’s abstraction from its implementation
  3. Composite: A tree structure/parent child of simple and composite objects
  4. Decorator: Add responsibilities to objects dynamically
  5. Façade: A single class that represents an entire complex system
  6. Flyweight: Minimize memory usage by sharing as much data as possible with similar objects
  7. Proxy: Provides a surrogate object, which references to other object

Behavioral Design Patterns
These patterns deal with Class & Object communication. There are as follows:

  1. Chain of Responsibility: A way of passing a request between a chain of objects
  2. Command: Encapsulate a command request as an object
  3. Interpreter: A way to include language elements in a program
  4. Iterator: Sequentially access the elements of a collection
  5. Mediator: Defines simplified communication between classes
  6. Memento: Capture and restore an object’s internal state
  7. Observer: A way of notifying change to a number of classes
  8. State: Alter an object’s behavior when its state changes
  9. Strategy: Encapsulates an algorithm inside a class
  10. Visitor: Defines a new operation to a class without change
  11. Template Method: Defer the exact steps of an algorithm to a subclass

That’s all about gof pattern.

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

3 thoughts on “Gang of Four (GOF) Design Patterns

  1. Its really helpful article. If possible give at list one example “how to use it in c#”
    Thanks for share.

Leave a Reply

Your email address will not be published. Required fields are marked *