Developer’s toolbox: 📒 Template Method Design Pattern

Vee Lesyk
Dots and Spaces
Published in
1 min readSep 2, 2019

Define the basic steps of an algorithm and allow the implementation of the individual steps to be changed.

Wikipedia says:

The template method is a method in a superclass, usually an abstract superclass, and defines the skeleton of an operation in terms of a number of high-level steps. These steps are themselves implemented by additional helper methods in the same class as the template method. The helper methods may be either abstract methods, for which case subclasses are required to provide concrete implementations, or hook methods, which have empty bodies in the superclass. Subclasses can (but are not required to) customize the operation by overriding the hook methods. The intent of the template method is to define the overall structure of the operation, while allowing subclasses to refine, or redefine, certain steps.

Github repo: link.

Swift

TemplateMethod.swift

TypeScript

TemplateMethod.ts
Template Method

P.S. We would be happy to see comments according to mistakes & typos.

--

--

Vee Lesyk
Dots and Spaces

#h+ #livemoredomore Adventurer. Unique experience wizard. Maker of things. Convergence commander. Information warlock. Problem solver. System: ☉; Planet: ♁.