πŸŽ„Are design patterns still relevant?🌟

Dec 14 2023

Back to 2023 Advent Calendar

What are design patterns?

Design patterns are a set of common solutions to common problems in software engineering.

They act as a common language for developers to communicate about common problems and solutions.

They were popularized by the book Design Patterns: Elements of Reusable Object-Oriented Software by the Gang of Four.

This was very popular during OOP times, but programming paradigms keep shifting.

It was OOP, then functional programming, then reactive programming etc.

List of patterns from this book

  • Creational
    • Abstract Factory
    • Builder
    • Factory Method
    • Prototype
    • Singleton
  • Structural
    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Facade
    • Flyweight
    • Proxy
  • Behavioral
    • Chain of Responsibility
    • Command
    • Interpreter
    • Iterator
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Template Method
    • Visitor

Are they still relevant?

Most of them are still relevant today, but often only in the context of a complex enterprise application written in Java.

Same kind of application that would use DDD (Domain Driven Design).

Let's go over a few of them. And next year, we'll have a separate blog post about each of the design patterns.

Singleton

If you want to have a single instance of a class, you can use the singleton pattern.

This is still relevant in all languages that support classes.

Of course depending on your language, you might have a better way to do this.

e.g in Go, you can just use a package level variable.

and in Python and Javascript, you can use a module level variable.

Visitor

The visitor pattern as it's described in the book is not too relevant anymore.

I've never seen it used in production.

However, the concept of a visitor is still very relevant.

For example, all AST libraries use the visitor pattern. e.g antlr4 and tree-sitter