Gang of Four (GOF) Design Patterns

Last Updated : 23 Oct, 2026

The Gang of Four Design Patterns is a set of solutions to common problems we encounter in software design and development. The term comes from the authors of the famous book “Design Patterns: Elements of Reusable Object-Oriented Software” by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, who are collectively known as Gang of Four.

  • GoF introduced 23 classic design patterns that help solve common problems in object-oriented software.
  • These patterns provide solutions to common design problems and help make software systems more modular, flexible and maintainable.

Types of GOF Design Patterns

These patterns are divided into three categories:

1

1. Creational Design Patterns

Creational Design Patterns are design patterns that provide standard ways to create objects while hiding the details of object creation from the client code. They make object creation more flexible, reusable, and maintainable.

Real-World Example: Think of ordering a Pizza at a restaurant. You simply choose the type of pizza you want, such as Margherita or Farmhouse. You do not need to know how the chef prepares the dough, adds toppings, or bakes the pizza. The chef handles all these steps for you.

Types

type-creation-design-pattern
  • Singleton pattern: Ensures that a class has only one instance within a defined scope and provides a global access point to that instance.
  • Factory Method pattern: Defines an interface for creating objects while allowing subclasses to decide which concrete class to instantiate.
  • Abstract Factory pattern: Provides an interface for creating families of related objects without specifying their concrete classes.
  • Prototype pattern: Creates new objects by copying existing objects rather than constructing them from scratch.
  • Builder pattern: Separates the construction of a complex object from its representation, often allowing objects to be constructed step by step.

2. Structural Design Patterns

Structural Design Patterns provide standard ways to combine classes and objects to form larger and more flexible structures. They focus on how different components are connected and work together.

Real-World Example: Think of building a house using different parts such as doors, windows, walls, and rooms. These parts are combined in a planned way so they work together as a complete house. If needed, one part can also be replaced without rebuilding the entire house.

Types

types_of_STRUCTURAL
  • Adapter Pattern: Converts the interface of an existing class into an interface expected by the client.
  • Bridge Pattern: Separates an abstraction from its implementation so they can vary independently.
  • Composite Pattern: Organizes individual objects and groups of objects into tree structures, allowing clients to treat them uniformly.
  • Decorator Pattern: Adds responsibilities to an object dynamically by wrapping it with other objects that share a compatible interface.
  • Facade Pattern: Provides a simplified interface to a complex system, hiding its inner complexity and making it easier to use.
  • Flyweight Pattern: Reduces memory usage by sharing reusable state among large numbers of similar objects.
  • Proxy Pattern: Provides a substitute or placeholder for another object to control access to it.

3. Behavioral Design Patterns

Behavioral Design Patterns define standard ways for objects to communicate and interact with each other. They help distribute responsibilities and manage the behavior of objects in a flexible way.

Real-World Example: Think of a restaurant where the customer, waiter, and chef have different responsibilities. The customer places an order with the waiter, and the waiter communicates it to the chef. Each person handles their own task while working together to complete the order.

Types

behavioral_design_patterns
  • Chain of Responsibility Pattern: Passes a request through a sequence of handlers until an appropriate handler processes it.
  • Command Pattern: Encapsulates a request as an object, allowing it to be stored, queued, logged, or reversed.
  • Interpreter Pattern: Defines a grammar and provides a way to interpret and evaluate expressions written in that language.
  • Iterator Pattern: Lets you access elements in a collection sequentially without exposing its internal structure.
  • Mediator Pattern: Centralizes communication between objects, reducing dependencies and simplifying interactions.
  • Memento Pattern: Captures an object’s state and allows it to be restored later, like saving and loading a snapshot.
  • Observer Pattern: One object (subject) notifies multiple observers of changes, enabling dynamic updates.
  • State Pattern: Lets an object change its behavior dynamically based on its current internal state.
  • Strategy Pattern: Defines a family of algorithms and allows switching between them at runtime for flexibility.
  • Template Method Pattern: Provides a fixed algorithm structure while allowing subclasses to override specific steps.
  • Visitor Pattern: Adds new operations to object structures without modifying the objects themselves.
Comment

Explore