...

/

Creating a Family of Related Algorithms

Creating a Family of Related Algorithms

Learn which design patterns make the code for related tasks more manageable.

Problem statement

Let’s imagine that we need to create a family of related algorithms. Each algorithm will have the same parameter types, and the same output object type, but will be composed of completely different internal logic.

We can just create many similar methods, but design patterns allow us to achieve our goal in a better way.

Suitable design patterns

Let’s discuss some design patterns suitable for creating a family of related algorithms.

Template Method

The Template Method design pattern is perhaps the simplest way of achieving the goal of defining a family of related algorithms.

The Template Method pattern is just a really standard usage of a standard object-oriented feature of inheritance. We define either a skeleton ...