An Introduction to Software Design Patterns

June 2, 2017

Software design patterns are a basic problem-solving method in software engineering: they provide a reasonable sequence of steps for reaching a goal. This post briefly covers why we need them, what they do, and their main building blocks.

What Is a Software Design Pattern

A software design pattern is, in essence, an abstract, well-reasoned set of steps for reaching a goal, defined in order to solve a problem.

Which pattern to use depends on the specific business scenario; each pattern has its own intent, motivation, and structure.

Who invented design patterns

The concept of patterns comes from architecture and was first proposed by Christopher Alexander. It was later applied to software development to address various problems in program design, with the Gang of Four (GoF) book as its earliest landmark. Since the end of the last century, the approach has been everywhere in medium and large software design and has become a common reference standard.

Why We Need Software Design Patterns

Software design patterns are a toolbox for solving problems, which is especially important in object-oriented problem settings.

Design patterns are also a shared language for communication. Imagine a colleague writes a large module in a purely procedural, function-by-function style, and the module now has to be handed over to someone else for maintenance. The new owner may face misunderstandings and other unknown risks (the proverbial "spaghetti code" mess). People understand structured, visual things more easily, and design patterns are a general methodology in that sense.

Some things to watch out for

Design patterns have many benefits, but they are not without drawbacks. The most common problem is misuse: some modern high-level languages offer better solutions that can replace a classic pattern. Another is overuse: a pattern only shows its value when it brings a meaningful improvement to the project. For example, in some business scenarios you can use the Facade pattern to provide a uniform interface and hide internal system complexity, but if the system's internals are not complex to begin with, there is no need to do so.

What Design Patterns Are There

Design patterns fall into three main categories:

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns

Their relationships are shown below:

Design Pattern

Creational Patterns

Creational patterns deal with object construction and improve code flexibility and reusability. Common ones include: Factory Method, Abstract Factory, Builder, Prototype, and Singleton.

Structural Patterns

Structural patterns describe how objects and data structures are assembled and composed. Common ones include: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, and Proxy.

Behavioral Patterns

Behavioral patterns handle efficient communication and delegation of responsibilities between objects. Common ones include: Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor, and Interpreter.