Skip to main content
Engineering LibreTexts

11.3: Design Patterns

  • Page ID
    32430
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Abstract Factory

    Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

    Source: Design Patterns [GHJV95].

    Referenced from: Look for the Contracts, Transform Client Type Checks.

    Adapter

    Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

    Source: Design Patterns [GHJV95].

    Referenced from: Present the Right Interface, Move Behavior Close to Data.

    Facade

    Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

    Source: Design Patterns [GHJV95].

    Referenced from: Eliminate Navigation Code, Split Up God Class.

    Factory Method

    Intent Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

    Source: Design Patterns [GHJV95].

    Referenced from: Look for the Contracts.

    Flyweight

    Intent Use sharing to support large numbers of fine-grained objects efficiently.

    Source: Design Patterns [GHJV95].

    Referenced from: Speculate about Design.

    Null Object

    Intent A Null Object provides a surrogate for another object that shares the same interface but does nothing. Thus, the Null Object encapsulates the implementation decisions of how to do nothing and hides those details from its collaborators

    Source: Null Object [Woo98].

    Referenced from: Introduce Null Object.

    Quantity

    Problem: Representing a value such as 6 feet or $5.

    Solution: Use a quantity type that includes both the amount and the unit. Currencies are a kind of unit.

    Source: Analysis Patterns: Reusable Objects Models [Fow97].

    Referenced from: Analyze the Persistent Data.

    Singleton

    Intent Ensure a class only has one instance, and provide a global point of access to it.

    Source: Design Patterns [GHJV95].

    Referenced from: Read all the Code in One Hour.

    State

    Intent Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

    Source: Design Patterns [GHJV95].

    Referenced from: Factor out State.

    State Patterns

    Intent The State Patterns pattern language refines and clarifies the State Pattern.

    Source: State Patterns [DA97].

    Referenced from: Factor out State.

    Strategy

    Intent Define a family of algorithms, encapsulate each one in a separate class, and define each class with the same interface so they can be interchangeable. Strategy lets the algorithm vary independently from clients that use it.

    Source: Design Patterns [GHJV95].

    Referenced from: Factor out Strategy.

    Template Method

    Intent Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

    Source: Design Patterns [GHJV95].

    Referenced from: Look for the Contracts.

    Visitor

    Intent Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

    Source: Design Patterns [GHJV95].

    Referenced from: Move Behavior Close to Data.


    This page titled 11.3: Design Patterns is shared under a CC BY-SA license and was authored, remixed, and/or curated by Serge Demeyer, Stéphane Ducasse, Oscar Nierstrasz.

    • Was this article helpful?