© Kelt Dockins 2017

Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_25

25. Template Method

Kelt Dockins

(1)Dolph, Arkansas, USA

$> git checkout template_method

Intent

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. The template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.1

Applications

The template method is useful when you have an algorithm that needs further instruction internally to run correctly. It fits well when an algorithm has steps, much like a cooking recipe. The Head First Design Patternsbook uses an example of making different caffeinated drinks. Making a cup of tea is very much like making a cup of coffee ...

Get Design Patterns in PHP and Laravel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.