Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Template Method

706

Published on

Object-oriented analysis and design(OOAD) and Design Pattern Slides UML Slides. for more slides refer www.scmGalaxy.com

Object-oriented analysis and design(OOAD) and Design Pattern Slides UML Slides. for more slides refer www.scmGalaxy.com

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
706
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
30
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Basic Floor Plan Example of Template Method The Template Method defines a skeleton of an algorithm in an operation, and defers some steps to subclasses. Home builders use the Template Method when developing a new subdivision. A typical subdivision consists of a limited number of floor plans, with different variations available for each floor plan. Within a floor plan, the foundation, framing, plumbing, and wiring will be identical for each house. Variation is introduced in the latter stages of construction to produce a wider variety of models.
• 2.
• Template Method
• 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.
Behavioral
• 3.
• Problem:
• Given a template method if we need to customize or redefine a particular set in the algorithm one may have to override the template function this causes duplication and an inefficient usage of template methods.
Behavioral <<Create>> DoCreateDocument() *
• 4. Illustration Behavioral * DoCreateDocument()
• 5. Solution
• A template method pattern gives a solution.
• A template method defines an algorithm in times of abstract operation the subclasses override to provide concrete behavior.
Behavioral : Template Method
• 6. Structure Behavioral TemplateMethod(){ }
• 7. Applicability
• To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary.
•
• When common behavior among subclasses should be factored and localized in a common class to avoid code duplication.
•
• To control subclasses extensions. You can define a template method that calls “hook” operations (see Consequences) at specific points, thereby permitting extensions only at those points.
Behavioral
• 8. Collaborations
•       ConcreteClass relies on abstractClass to implement the invariant steps of the algorithm.
Behavioral
• 9. Consequences
• 1. Concrete operations
• 2. Concrete AbstractClass operations
• 3. Primitive operations
• 4. Factory methods
• 5. Hook operations, which provide default behavior that subclasses can extend if necessary. A hook operation often does nothing by default.
Behavioral
• 10. Model
• 11. Related Patterns
• Factory Methods are often called by template methods. In the Motivation example, the factory method DoCreateDocument is called by the template method OpenDocument.
• Strategy: Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm.
Behavioral