The Gang of Four (GOF) Design Patterns refer to a set of 23
classic software design patterns that were introduced in the
book "Design Patterns: Elements of Reusable Object-Oriented
Software" by Erich Gamma, Richard Helm, Ralph Johnson,
and John Vlissides, often referred to as the "Gang of Four."
These patterns are categorized into three main groups:
Creational, Structural, and Behavioral patterns. Each pattern
addresses a specific recurring design problem in software
development and provides a proven solution or template to
solve it.
Creational Patterns
Creational patterns focus on object creation mechanisms,
trying to create objects in a manner suitable to the situation.
They abstract the instantiation process and make a system
independent of how its objects are created, composed, and
represented.
1. Singleton Pattern: Ensures a class has only one
instance and provides a global point of access to it.
2. Factory Method Pattern: Defines an interface for
creating an object, but lets subclasses decide which class
to instantiate.
3. Abstract Factory Pattern: Provides an interface for
creating families of related or dependent objects without
specifying their concrete classes.
4. Builder Pattern: Separates the construction of a
complex object from its representation, allowing the
same construction process to create various
representations.
5. Prototype Pattern: Specify the kinds of objects to
create using a prototypical instance, and create new
objects by copying this prototype.
Structural Patterns
Structural patterns are concerned with how classes and objects
are composed to form larger structures.
1. Adapter Pattern: Converts the interface of a class into
another interface clients expect. Allows classes to work
together that could not otherwise because of
incompatible interfaces.
2. Bridge Pattern: Decouples an abstraction from its
implementation so that the two can vary independently.
3. Composite Pattern: Composes objects into tree
structures to represent part-whole hierarchies. Allows
clients to treat individual objects and compositions of
objects uniformly.
4. Decorator Pattern: Attaches additional responsibilities
to an object dynamically. Provides a flexible alternative
to subclassing for extending functionality.
5. Facade Pattern: Provides a unified interface to a set of
interfaces in a subsystem. Defines a higher-level
interface that makes the subsystem easier to use.
6. Flyweight Pattern: Uses sharing to support large
numbers of fine-grained objects efficiently.
7. Proxy Pattern: Provides a surrogate or placeholder for
another object to control access to it.
Behavioral Patterns
Behavioral patterns are concerned with algorithms and the
assignment of responsibilities between objects.
1. Chain of Responsibility Pattern: Avoids coupling the
sender of a request to its receiver by giving more than
one object a chance to handle the request.
2. Command Pattern: Encapsulates a request as an object,
thereby letting you parameterize clients with different
requests, queue or log requests, and support undoable
operations.
3. Interpreter Pattern: Defines a representation for
grammar of a language and provides an interpreter to
interpret sentences in the language.
4. Iterator Pattern: Provides a way to access the elements
of an aggregate object sequentially without exposing its
underlying representation.
5. Mediator Pattern: Defines an object that encapsulates
how a set of objects interact. Promotes loose coupling
by keeping objects from referring to each other
explicitly.
6. Memento Pattern: Without violating encapsulation,
captures and externalizes an object's internal state so that
the object can be restored to this state later.
7. Observer Pattern: Defines a one-to-many dependency
between objects so that when one object changes state,
all its dependents are notified and updated
automatically.
8. State Pattern: Allows an object to alter its behavior
when its internal state changes. The object will appear to
change its class.
9. Strategy Pattern: Defines a family of algorithms,
encapsulates each one, and makes them interchangeable.
Lets the algorithm vary independently from clients that
use it.
10. Template Method Pattern: Defines the skeleton of an
algorithm in a method, deferring some steps to
subclasses. Allows subclasses to redefine certain steps
of an algorithm without changing the algorithm's
structure.
11. Visitor Pattern: Represents an operation to be
performed on the elements of an object structure. Allows
you to define a new operation without changing the
classes of the elements on which it operates.
Application of GOF Design Patterns
• Reusable Solutions: GOF patterns provide reusable
solutions to common problems in software design,
promoting code reuse and maintainability.
• Common Vocabulary: They establish a common
vocabulary and standard way of describing design
problems and solutions, facilitating communication
among developers.
• Proven Practices: These patterns are based on proven
practices and principles of object-oriented design,
making them reliable and widely applicable.