Search

What is a design pattern?

What is a design pattern?

A design pattern is a proven design solution to a common problem faced by software developers. Design patterns became popular with the rise of Object Oriented Analysis and Design (OOAD). Design patterns are designed to help developers deliver higher quality, more easily maintained software products in less time and at lower cost.

Design patterns are:

  • encapsulated - They embody design knowledge regarding collaboration of classes and objects, distribution of
  • responsibility, and other design issues.
  • object-oriented - They incorporate OOAD principles—e.g., low coupling, high cohesion.
  • reusable - They are adaptable, flexible, general solutions to classes of problems with broad applicability. Design patterns simplify the task facing the developer.

    How did design patterns originate?

    The history of design patterns is quite short. They originated as an architectural concept proposed by Christopher Alexander in the late nineteen seventies (ca. 1977). Kent Beck and Ward Cunningham experimented with the notion of applying patterns to computer programming in the late nineteen eighties (ca. 1987). Design patterns did not become widely used in computer science until after Design Patterns: Elements of Reusable Object-Oriented Software by the so-called Gang of Four was published in 1994.

    How are design patterns classified?

    Design patterns are categorized to facilitate learning and extending them. They are classified in terms of the underlying problems they address, i.e. according to usage.

    The three main design pattern categories are:

  • Behavioral design patterns - characterize the manner of class and object interaction and how responsibilities are distributed among them.
  • Creational design patterns - address the object creation process. Creational design patterns encapsulate knowledge about how, when, and by whom an instance is created.
  • Structural design patterns - address the composition of classes and objects. Design patterns vary both in granularity and level of abstraction.

    Behavioral design patterns

  • Chain of Responsibility Define a method of passing a request among a chain of objects.
  • Command Encapsulate a command request in an object.
  • Interpreter Allow inclusion of language elements in an application.
  • Iterator Enable sequential access to collection elements.
  • Mediator Define simplified communication between classes.
  • Memento Save and restore the internal state of an object.
  • Observer Define a scheme for notifying objects of changes to another object.
  • State Alter the behavior of an object when its state changes.
  • Strategy Encapsulate an algorithm inside a class.
  • Template Method Allow subclasses to redefine the steps of an algorithm.
  • Visitor Define a new operation on a class without changint it.

    Creational design patterns

  • Abstract Factory Encapsulate a set of analogous factories that produce families of objects.
  • Builder Encapsulate the construction of complex objects from their representation; so, the same building process can create various representations by specifying only type and content.
  • Factory Method Allow subclasses to "decide" which class to instantiate.
  • Prototype Create an initialized instance for cloning or copying.
  • Singleton Ensure that only a single instance of a class exists and provide a single method for gaining access to it.

    Structural design patterns

  • Adapter Adapt an interface to an expected interface.
  • Bridge Decouple an interface from its implementation.
  • Composite Create a tree structure for part-whole hierarchies.
  • Decorator Extend functionality dynamically.
  • Façade (Facade) Simplify usage by defining a high-level interface.
  • Flyweight Support fine-grained objects efficiently by sharing.
  • Proxy Represent an object with another object for access control.