Skip to main content
Abstract Document

Intent

The Abstract Document design pattern is a structural design pattern that aims to provide a consistent way to handle hierarchical and tree-like data structures by defining a common interface for various document types. It separates the core document structure from specific data formats, enabling dynamic updates and simplified maintenance.


iluwatarAbout 4 minStructuralAbstractionDecouplingDynamic typingEncapsulationExtensibilityPolymorphism
Acyclic Visitor

Intent

The Acyclic Visitor pattern decouples operations from an object hierarchy, allowing you to add new operations without modifying the object structure directly.

Explanation

Real world example

An analogous real-world example of the Acyclic Visitor pattern is a museum guide system. Imagine a museum with various exhibits like paintings, sculptures, and historical artifacts. The museum has different types of guides (audio guide, human guide, virtual reality guide) that provide information about each exhibit. Instead of modifying the exhibits every time a new guide type is introduced, each guide implements an interface to visit different exhibit types. This way, the museum can add new types of guides without altering the existing exhibits, ensuring that the system remains extensible and maintainable without forming any dependency cycles.


iluwatarAbout 3 minBehavioralDecouplingExtensibilityInterfaceObject composition
Bridge

Also known as

  • Handle/Body

Intent

Decouple an abstraction from its implementation so that the two can vary independently.

Explanation

Real-world example

A real-world example of the Bridge design pattern can be found in the remote control and television relationship.

Imagine a universal remote control (abstraction) that can operate different brands and types of televisions (implementations). The remote control provides a consistent interface for operations like turning on/off, changing channels, and adjusting the volume. Each television brand or type has its own specific implementation of these operations. By using the Bridge pattern, the remote control interface is decoupled from the television implementations, allowing the remote control to work with any television regardless of its brand or internal workings. This separation allows new television models to be added without changing the remote control's code, and different remote controls can be developed to work with the same set of televisions.


iluwatarAbout 4 minStructuralAbstractionDecouplingExtensibilityGang of FourObject composition
Command

Also known as

  • Action
  • Transaction

Intent

The Command design pattern encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations. It also allows for the support of undoable operations.


iluwatarAbout 3 minBehavioralDecouplingExtensibilityGang of FourUndo
Curiously Recurring Template Pattern

Also known as

  • CRTP
  • Mixin Inheritance
  • Recursive Type Bound
  • Recursive Generic
  • Static Polymorphism

Intent

Curiously Recurring Template Pattern (CRTP) is used to achieve a form of static polymorphism by having a class template derive from a template instantiation of its own class, allowing method overriding and polymorphic behavior at compile time rather than at runtime.


iluwatarAbout 3 minStructuralCode simplificationExtensibilityGenericIdiomInstantiationPolymorphismRecursion
Decorator

Also known as

  • Smart Proxy
  • Wrapper

Intent

The Decorator pattern allows for the dynamic addition of responsibilities to objects without modifying their existing code. It achieves this by providing a way to "wrap" objects within objects of similar interface.


iluwatarAbout 3 minStructuralEnhancementExtensibilityGang of FourObject compositionWrapping
Extension Objects

Also known as

  • Interface Extensions

Intent

The Extension Objects pattern allows for the flexible extension of an object's behavior without modifying its structure, by attaching additional objects that can dynamically add new functionality.

Explanation


iluwatarAbout 3 minStructuralEncapsulationExtensibilityObject compositionPolymorphism
Feature Toggle

Also known as

  • Feature Flag
  • Feature Switch

Intent

A technique used in software development to control and manage the rollout of specific features or functionality in a program without changing the code. It can act as an on/off switch for features depending on the status or properties of other values in the program. This is similar to A/B testing, where features are rolled out based on properties such as location or device. Implementing this design pattern can increase code complexity, and it is important to remember to remove redundant code if this design pattern is being used to phase out a system or feature.


iluwatarAbout 2 minBehavioralDecouplingExtensibilityFeature managementScalability
Pipeline

Also known as

  • Chain of Operations
  • Processing Pipeline

Intent

The Pipeline design pattern is intended to allow data processing in discrete stages, where each stage is represented by a different component and the output of one stage serves as the input for the next.


iluwatarAbout 3 minBehavioralAPI designData processingDecouplingExtensibilityFunctional decompositionScalability
Role Object

Intent

To dynamically assign roles to objects, enabling them to change behavior and responsibilities at runtime.

Explanation

Real world example

Imagine a restaurant where staff members can take on different roles based on the needs of the moment. For example, an employee could be a server, a cashier, or a kitchen helper depending on the situation. When the restaurant is busy, a server might also take on the role of a cashier to help process payments quickly. Later, the same employee might assist in the kitchen during a rush. This flexibility allows the restaurant to dynamically allocate responsibilities to meet real-time demands, enhancing efficiency and customer satisfaction. The Role Object pattern in software mimics this by allowing objects to assume different roles and behaviors at runtime, providing similar flexibility and adaptability.


iluwatarAbout 3 minStructuralAbstractionDecouplingExtensibilityInterfaceObject compositionPolymorphismRuntime