Post

What is a Design Pattern?

In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into code. Instead, it is a description or template for solving a problem that can be used in many different situations. Design patterns are formalised best practices that the programmer can use to solve common problems when designing an application or system.

Design patterns have evolved, and they provide the best solutions to particular problems faced during software development. Learning these patterns helps inexperienced developers to learn software design in an easy and faster way.

History of Design Patterns

In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, published a book titled Design Patterns: Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. The book is divided into two parts, with the first two chapters exploring the capabilities and pitfalls of object-oriented programming and the remaining chapters describing 23 classic software design patterns.

The book has been influential to software engineering and is an essential source for object-oriented design theory and practice. More than 500,000 copies have been sold in English and 13 other languages.

The authors are often referred to as the Gang of Four (GoF).

Types of Design Patterns

Design patterns can be classified into three categories:

Creational design patterns

Creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. 

  • Abstract factory design pattern
    Creates an instance of several families of classes
  • Builder design pattern
    Separates object construction from its representation
  • Factory method design pattern
    Creates an instance of several derived classes
  • Prototype design pattern
    A fully initialised formalised instance to be copied or cloned
  • Singleton design pattern
    A class of which only a single instance can exist

Structural design patterns

Structural design patterns ease the design by identifying a simple way to realise formalised relationships among entities.

  • Adapter design pattern
    Match interfaces of different classes
  • Bridge design pattern
    Separates an object’s interface from its implementation
  • Composite design pattern
    A tree structure of simple and composite objects
  • Decorator design pattern
    Add responsibilities to objects dynamically
  • Facade design pattern
    A single class that represents an entire subsystem
  • Flyweight design pattern
    A fine-grained instance used for efficient sharing
  • Proxy design pattern
    An object representing another object

Behavioural design patterns

Behavioural design patterns are design patterns that identify common communication patterns among objects. By doing so, these patterns increase flexibility in carrying out communication.

  • Chain of responsibility design pattern
    A way of passing a request between a chain of objects
  • Command design pattern
    Encapsulate a command request as an object
  • Iterator design pattern
    Sequentially access the elements of a collection
  • Mediator design pattern
    Defines simplified communication between classes
  • Memento design pattern
    Capture and restore an object's internal state
  • Observer design pattern
    A way of notifying change to several classes
  • State design pattern
    Alter an object's behaviour when its state changes
  • Strategy design pattern
    Encapsulates an algorithm inside a class
  • Template method design pattern
    Defer the exact steps of an algorithm to a subclass

Memento Design Pattern

Memento is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation.