Skip to content

Commit 15e7002

Browse files
committed
Update README.md
1 parent 39371a2 commit 15e7002

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,12 @@
218218
##Template method
219219
**Intent:** Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
220220

221+
![alt text](https://github.com/iluwatar/java-design-patterns/blob/master/template-method/etc/template-method.jpg "Template Method")
222+
223+
**Applicability:** The Template Method pattern should be used
224+
* to implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary
225+
* when common behavior among subclasses should be factored and localized in a common class to avoid code duplication. This is good example of "refactoring to generalize" as described by Opdyke and Johnson. You first identify the differences in the existing code and then separate the differences into new operations. Finally, you replace the differing code with a template method that calls one of these new operations
226+
* to control subclasses extensions. You can define a template method that calls "hook" operations at specific points, thereby permitting extensions only at those points
227+
221228
##Visitor
222229
**Intent:** Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

0 commit comments

Comments
 (0)