Basic Floor Plan Example of  Template Method The  Template   Method  defines a skeleton of an algorithm in an operation, a...
<ul><li>Template Method </li></ul><ul><li>Intent </li></ul><ul><li>  </li></ul><ul><li>Define the skeleton of an algorithm...
<ul><li>Problem: </li></ul><ul><li>Given a template method if we need to customize or redefine a particular set in the alg...
Illustration Behavioral * DoCreateDocument()
Solution <ul><li>A template method pattern gives a solution. </li></ul><ul><li>A template method defines an algorithm in t...
Structure Behavioral TemplateMethod(){ }
Applicability <ul><li>To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the...
Collaborations <ul><li>      ConcreteClass relies on abstractClass to implement the invariant steps of the algorithm. </l...
Consequences <ul><li>1.  Concrete operations  </li></ul><ul><li>2.  Concrete AbstractClass operations </li></ul><ul><li>3....
Model
Related Patterns <ul><li>Factory Methods are often called by template methods. In the Motivation example, the factory meth...
Upcoming SlideShare
Loading in …5
×

Template Method

935 views
855 views

Published on

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

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
935
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Template Method

  1. 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. 2. <ul><li>Template Method </li></ul><ul><li>Intent </li></ul><ul><li>  </li></ul><ul><li>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. </li></ul>Behavioral
  3. 3. <ul><li>Problem: </li></ul><ul><li>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. </li></ul>Behavioral <<Create>> DoCreateDocument() *
  4. 4. Illustration Behavioral * DoCreateDocument()
  5. 5. Solution <ul><li>A template method pattern gives a solution. </li></ul><ul><li>A template method defines an algorithm in times of abstract operation the subclasses override to provide concrete behavior. </li></ul>Behavioral : Template Method
  6. 6. Structure Behavioral TemplateMethod(){ }
  7. 7. Applicability <ul><li>To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary. </li></ul><ul><li>  </li></ul><ul><li>When common behavior among subclasses should be factored and localized in a common class to avoid code duplication. </li></ul><ul><li>  </li></ul><ul><li>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. </li></ul>Behavioral
  8. 8. Collaborations <ul><li>      ConcreteClass relies on abstractClass to implement the invariant steps of the algorithm. </li></ul>Behavioral
  9. 9. Consequences <ul><li>1. Concrete operations </li></ul><ul><li>2. Concrete AbstractClass operations </li></ul><ul><li>3. Primitive operations </li></ul><ul><li>4. Factory methods </li></ul><ul><li>5. Hook operations, which provide default behavior that subclasses can extend if necessary. A hook operation often does nothing by default. </li></ul>Behavioral
  10. 10. Model
  11. 11. Related Patterns <ul><li>Factory Methods are often called by template methods. In the Motivation example, the factory method DoCreateDocument is called by the template method OpenDocument. </li></ul><ul><li>Strategy: Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm. </li></ul>Behavioral

×