Merge branch 'master' of https://github.com/MihaiTheCoder/BehavioralPatterns.git
This commit is contained in:
11
README.md
11
README.md
@@ -415,6 +415,17 @@ The strategy pattern defines a family of algorithms, encapsulates each algorithm
|
|||||||
In software engineering, the template method pattern is a behavioral design pattern that defines the program skeleton of an algorithm in an operation,
|
In software engineering, the template method pattern is a behavioral design pattern that defines the program skeleton of an algorithm in an operation,
|
||||||
defering some steps to subclasses. It lets one redefine certain steps of an algorithm without changing the algorithm's structure.
|
defering some steps to subclasses. It lets one redefine certain steps of an algorithm without changing the algorithm's structure.
|
||||||
Template pattern works using 'the Hollywood principle' from the base class point of view: 'Don't call us, we'll call you'
|
Template pattern works using 'the Hollywood principle' from the base class point of view: 'Don't call us, we'll call you'
|
||||||
|
|
||||||
|
Class diagram:
|
||||||
|
legend:
|
||||||
|
* \# is for protected method
|
||||||
|
* Italic is for abstract method
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Sequence diagram:
|
||||||
|
|
||||||
|

|
||||||
### b. When to use Template method pattern
|
### b. When to use Template method pattern
|
||||||
* Let subclasses implement (through method overriding) behavior that can vary.
|
* Let subclasses implement (through method overriding) behavior that can vary.
|
||||||
* Avoid duplication in the code: the general workflow structure is implemented once in the abstract class's algorithm, and necessary variations are implemented in each of the subclasses.
|
* Avoid duplication in the code: the general workflow structure is implemented once in the abstract class's algorithm, and necessary variations are implemented in each of the subclasses.
|
||||||
|
|||||||
Reference in New Issue
Block a user