Ir para o conteúdo principal

← todas as notas

Gang of Four Design Patterns

The 23 design patterns catalogued by Gamma, Helm, Johnson and Vlissides in Design Patterns: Elements of Reusable Object-Oriented Software (1994).

Creational
#

  1. Abstract Factory — provide an interface for creating families of related objects without specifying their concrete classes.
  2. Builder — separate the construction of a complex object from its representation, so the same process can create different representations.
  3. Factory Method — define an interface for creating an object, but let subclasses decide which class to instantiate.
  4. Prototype — create new objects by cloning an existing instance.
  5. Singleton — ensure a class has only one instance and provide a global point of access to it.

Structural
#

  1. Adapter — convert the interface of a class into another interface clients expect.
  2. Bridge — decouple an abstraction from its implementation so the two can vary independently.
  3. Composite — compose objects into tree structures to represent part-whole hierarchies, letting clients treat individual objects and compositions uniformly.
  4. Decorator — attach additional responsibilities to an object dynamically, as an alternative to subclassing.
  5. Facade — provide a simplified interface to a complex subsystem.
  6. Flyweight — use sharing to support large numbers of fine-grained objects efficiently.
  7. Proxy — provide a surrogate or placeholder for another object to control access to it.

Behavioral
#

  1. Chain of Responsibility — pass a request along a chain of handlers until one processes it.
  2. Command — encapsulate a request as an object, allowing parameterization, queuing, and undo.
  3. Interpreter — define a grammar and an interpreter that uses the grammar to interpret sentences.
  4. Iterator — access elements of a collection sequentially without exposing its underlying representation.
  5. Memento — capture an object’s internal state so it can be restored later without violating encapsulation.
  6. Mediator — define an object that encapsulates how a set of objects interact, promoting loose coupling.
  7. Observer — define a one-to-many dependency so that when one object changes state, all dependents are notified.
  8. Strategy — define a family of algorithms, encapsulate each one, and make them interchangeable at runtime.
  9. State — allow an object to alter its behavior when its internal state changes, appearing to change its class.
  10. Template Method — define the skeleton of an algorithm in a base class, letting subclasses override specific steps.
  11. Visitor — represent an operation to be performed on elements of an object structure without changing the classes.