Introduction to Design Patterns

Published on 14 February, 2021

'Patterns'

Photo by Ferdinand Stöhr on Unsplash


The purpose of this series is to synthesize the main points of each design pattern into short content blocks that we could later get back to when we have doubs about implementing them.

The big problem I see with people trying to use design patterns, it's the law of the instrument/hammer or better off, Maslow's hammer, as he supposedly said:

I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.

Sure, there's much more criticism to it, but it's not the subject of this post to discuss such controversies.

Some people praise them with their lives while others say that they are of little or no avail. Personally, I think they are really useful, but we have to be wary to not over-implement them; since that could lead us to a codebase that could become really hard to maintain.

Truth is, when implemented correctly, they can be real life-changing solutions to problems otherwise really hard to solve. On the other hand, when they are not, a dreadful feeling will run up your spine everytime you bump into that awful implementation that you ran to put on your code, and a few weeks later you realised all the side effects and implications of it but have no time to revert.

Classification

Patterns can be classified by many ways, but I'll focus on what I think is the most common way to be categorized: by its purpose.

  • Creational patterns: Provide us with ways to create objects and simple structures with the aim to reuse our code, usually hiding the creation logic away.

    • Factory method
    • Abstract Factory
    • Builder
    • Prototype
    • Singleton
  • Structural patterns: Provide us with ways to make objects into more complex structures, usually through composition and acquiring new functionalities in the process.

    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Facade
    • Flyweight
    • Proxy
  • Behavioral patterns: These ones tend to either assign responsibilities or establish some sort of communication between objects/components.

    • Chain of responsibility
    • Command
    • Iterator
    • Interpreter
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Template method
    • Visitor

This are the famous 23 Gang of Four's Design Patterns

Topics

arch linux1 postaws1 postcloud computing1 postdesign patterns1 postfunctional programming1 postjavascript4 postsjest1 postregexp1 posttesting1 post