Intent:
- Define the skeleton of an algorithm in an operation, deferring some steps to subclasses and let subclasses redefine steps of an algorithm without changing the algorithm's structure.
- To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behaviro that can vary.
- Avoid code duplication.
- To control subclasses exensions.
AbstractClass
- defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm.
- implements a template method defining the skeleton of an algorithm.
- The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
- implements the primitive opreations to carry out subclass-specific steps of the algorithm.
ConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm
- Reuses code
- Factors common behavior.
- Realizes "HR" principle.
- Application
- MyApplication
- Print Document
- Manufacture
- Approve loan:
- bank history
- credit score from credit card companies
- other loan history
- evaluate assets
- income in the future
- Make Pizza
- take order & money
- send order to kitchen
- receive pizza from kitchen
- deliver pizza
- clean table
No comments:
Post a Comment