Design Patterns Overview

Design Patterns Overview

Design Patterns Serie

What are Design Patterns?

Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in the code.

Software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is a template for how to solve a problem that can be used in many different problems, and situations.

Design patterns are best practices that the programmer can use to solve common problems when designing an application or system.

History of Design Patterns

Patterns originated as an architectural concept by Christopher Alexander as early as 1977.
In 1987, Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns in programming and showed their results at the OOPSLA conference that year.
In the following years, Beck, Cunningham and others followed up on this work.

Design patterns gained popularity in computer science after the book "Design Patterns: Elements of Reusable Object-Oriented Software" was published in 1994 by those who called themselves "Gang of Four".
At the same year, the first Pattern Languages of Programming Conference was held.

Classification

Design patterns had originally been categorized into 3 main classifications based on the kind of problem they solve :

  • Creational patterns provide the ability to create objects based on a required criterion and in a controlled way.
  • Structural patterns are about organizing different classes and objects to form larger structures and provide new functionality.
  • Behavioral patterns are about identifying common communication ways between objects and realizing these patterns.

Creational Patterns

Creational design patterns are design patterns that deal with object creation mechanisms, creating objects in a manner suitable to the situation.
Object creation could result in design problems or added complexity to the design.
Creational design patterns solve this problem by somehow controlling this object creation.

Types

  • Abstract Factory : Creates an instance of several families of classes.
  • Builder : Separates object construction from its representation.
  • Factory Method : Creates an instance of several derived classes.
  • Singleton : Involves a single class which is responsible to create an object while making sure that only a single object gets created.
  • Object Pool : Avoid expensive creation and release of resources by recycling objects that are no longer in use.
  • Prototype : A fully initialized instance to be copied or cloned (like a blueprint).

Structural patterns

Structural design patterns explain how to assemble objects and classes into larger structures, and at the same time keep these structures efficient and flexible.

Types

  • Adapter Pattern : Adapting an interface into another according to client expectation.
  • Composite Pattern : Allowing clients to operate on a hierarchy of objects. It describes a group of objects that are treated the same way as a single instance of the same type of object.
  • Decorator Pattern : Adding functionality to an object dynamically.
  • Bridge Pattern : Allowing the Separation of abstraction (interface) from implementation.
  • Facade Pattern : Hiding the complexities of the system, and providing an interface to the client using which the client can access the system.
  • Flyweight Pattern : Reusing an object by sharing it to support large numbers of fine-grained objects efficiently.
  • Proxy Pattern : Representing another intermediary object that acts as an interface to another resource to reduce the burden upon it.

Behavioural patterns

Behavioural design patterns identify common communication patterns between objects and realize these patterns. They increase flexibility in carrying out this communication.

Types

  • Chain of Responsibility Pattern : Creates a chain of receiver objects for a request and at the same time it decouples the sender and the receiver of a request based on the request type.
  • Command Pattern : Encapsulates a request as an object, by letting us parameterize other objects with different requests.
  • Interpreter Pattern : Provides a way to evaluate language grammar or expression.
  • Iterator Pattern : Provides a way to access the elements of an aggregate object without exposing its underlying representation.
  • Mediator Pattern : Used to reduce communication complexity between multiple objects or classes.
  • Memento Pattern : Lets us save and restore the previous state of an object without revealing the details of its implementation.
  • Observer Pattern : Defines a one-to-many dependency between objects. So, all of that object dependents are notified and updated automatically.
  • State Pattern : Allows an object to alter its behaviour when its internal state changes.
  • Strategy Pattern : Used when we have multiple algorithms for a specific task and the client decides the desired implementation to be used at runtime.
  • Template Pattern : Defines an algorithm as a skeleton of operations leaving the child classes to implement the details.
  • Visitor Pattern : Defines a new operation without introducing modifications to an existing object structure.
  • Null Object : Describes the uses of the objects with no referenced value and their behaviour.

Thank you, and goodbye.