Allison Machado Gonçalves

Allison Machado Gonçalves


Practical Design Patterns

Table of Contents

Introduction πŸ’‘

This is a simple an non exhaustive list of the most frequently used design patterns I had the chance to spot on real world applications over the years. 🐧


Strategy Pattern πŸ“Š

Used when it's desirable to change a concrete functionality implementation by changing the app configuration.

Imagine you are developing a traditional chatbot that needs to understand language to route it's conversation branching. The system that can understand language (NLU) can be implemented by different providers (google, ibm-watson, azure). Therefore, your code should wrap those concrete implementations into an application interface allowing developers to change the provider without changing the client logic.

Inversion of Control πŸ”ƒ

This design principle is used to reduce the coupling between components in a system. Instead of a class or module creating and managing its dependencies, they rely on those being injected - often by requesting interfaces. The responsibility of managing dependencies is given to an external entity, like a framework or container. This pattern makes it notoriously easier to write unit tests.

Several frameworks are well-known for their robust implementation of Inversion of Control (IoC) and some relevant examples are the Java Spring and JS Angular.

Template Method πŸ“

The Template Method pattern defines the skeleton of an algorithm in a superclass, but allows subclasses to override specific steps of the algorithm without changing its structure.

Imagine you are building a learning application, that organizes it's courses into learning sections, which are Entities saved in a database. Those share some basic characteristics and functionality, like common properties and being part of a hierarchical structure, which are defined in the base abstract class and methods. However, specific rules, like how many children or question each step should hold, are implemented by the subclasses.

Chain of Responsibility πŸ‘¬

This design pattern allows a request to be passed along a chain of handlers. Each handler in the chain decides whether to process the request, enrich it and/or pass it to the next handler.

This is commonly supported by most modern back end frameworks, making it easy to define functions that filter data or apply some pre-processing logic that may be required by down stream processes.

Singleton Pattern 1️⃣

The Singleton design pattern is a creational pattern that ensures a class has only one instance and provides a global point of access to that instance. This is useful when exactly one object is needed to coordinate actions across a system, such as a connection pool manager or a logging service.


References πŸ“š