mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-26 06:19:20 +02:00
18 lines
712 B
Markdown
18 lines
712 B
Markdown
# Template Method
|
|
|
|
## Purpose
|
|
|
|
Template Method is a behavioral design pattern.
|
|
|
|
Perhaps you have encountered it many times already. The idea is to let subclasses of this abstract template "finish" the behavior of an algorithm.
|
|
|
|
A.k.a the "Hollywood principle": "Don't call us, we call you." This class is not called by subclasses but the inverse.
|
|
How? With abstraction of course.
|
|
|
|
In other words, this is a skeleton of algorithm, well-suited for framework libraries. The user has just to implement one method and the superclass do the job.
|
|
|
|
It is an easy way to decouple concrete classes and reduce copy-paste, that's why you'll find it everywhere.
|
|
|
|
## UML Diagram
|
|
|
|
 |