Java

Design Patterns


Design patterns are a collection of abstract solutions to recurrent problems in object-oriented software development. These solutions are presented like templates that can be applied in many situations and programming languages, but with similar structures, providing a design which contributes to system’s flexibility, extensibility, portability and code reuse.

Elements of a Design Pattern

In general, a design pattern has four essential elements:

  • Name: a handle we can use to describe a design problem, its solutions and the consequences in a word or two. It gives the possibility to communicate with our colleges and create documentations.
  • Problem: describes when to apply the pattern, by explaining the problem and its context. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
  • Solution: describes the elements of design to solve the problem, their relationships, responsibilities and collaborations. It describes how to arrange these elements to solve the given problem.
  • Consequences: describes the results and trade-offs of applying the pattern. The consequences usually consist of space and time trade-offs, and sometimes language and implementation issues, becoming a critical concern for evaluating a design alternative.

Organization of Design Patterns

Design patterns can be divided into three types:

  • Creational: abstract the instantiation process. How objects are created, composed and represented become system independent, by hiding its implementation details under the use of inheritance, giving you lot of flexibility and taking away complex object instantiation processes.
  • Structural: are concerned with how classes and objects are composed to larger structures. They describe ways to compose objects to realise new functionalities without adding complexity while guaranteeing flexibility, to avoid ending up with “Frankenstein” classes.
  • Behavioural: are focused on algorithms and the assignment of responsibilities between objects. They characterise complex control flow that’s difficult to follow at run-time, then shift your focus away from the said flow to let you concentrate just on the way objects communicate to each other.

List of Design Patterns

I’m going to make a compilation of design patterns dividing them by its three types and updating the list below with links. The list is based on GoF (Gang of Four, authors of the book Design Patterns: Elements of Reusable Object-Oriented Software) and another great complementary sources of design patterns content. It starts with the Builder design pattern:

Creational

Structural

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Behavioural

  • Chain of Responsability
  • Command
  • Double Dispatch
  • Hook Classes
  • Hook Method
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Null Object
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

Any suggestions are welcome!
Hope it helps, cya!

bgasparotto

View Comments

  • Thank you for this! A very good intro for me. Enjoyed the breakdown of what goes into a
    design pattern.

  • Congratulations Bruno!!! It's a good article to introduce Design Patterns.
    Best regards!

    • Thanks Alexandre! I'm going to release a new pattern explanation really soon!

Recent Posts

Python function decorator

This guide will show you how to create a Python function decorator with a few…

2 years ago

Got permission denied while trying to connect to the Docker daemon socket

This guide will show you how to fix the error Got permission denied while trying…

2 years ago

Python virtual environment on Intellij IDEA

This guide will show you how to create a Python virtual environment on Intellij IDEA…

2 years ago

Find and kill processes on Linux and Mac by port number

This tutorial will quickly show you how to to find and kill processes on Linux,…

2 years ago

Python: Relocation R_X86_64_PC32 against symbol can not be used when making a shared object Error

This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…

2 years ago

Kubernetes useful commands

I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…

2 years ago