The Template Method - PowerPoint PPT Presentation

About This Presentation
Title:

The Template Method

Description:

Diagram: http://www.dofactory.com/Patterns/PatternTemplate.aspx. How is it Structured? ... http://www.dofactory.com/Patterns/PatternTemplate.aspx ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 10
Provided by: sinclair
Learn more at: http://www.cs.rpi.edu
Category:
Tags: aspx | method | template

less

Transcript and Presenter's Notes

Title: The Template Method


1
The Template Method
  • By Sinclair Schuller

2
What is the Template Method?
  • Skeleton definition of an algorithm
  • Allows redefinition of predetermined points
  • Preserves structural integrity of algorithm

3
Why is it Useful?
  • Allows for the factoring out of common behavior
  • Presents a clean method for implementing
    algorithms
  • Allows for code reuse

4
How is it Structured?
  • Participants
  • Abstract Class
  • Concrete Class
  • Operations Are
  • Hooks
  • Or
  • Abstract

Diagram http//www.dofactory.com/Patterns/Patter
nTemplate.aspx
5
How is it Structured?
  • Template method is implemented with calls to
    primitive operations
  • Primitive operations either allow full (if
    abstract) or partial (if hook) control to
    subclass
  • Keep it simple (minimize number of primitive
    operations)

6
Example
  • void ShapeDraw()
  • InitializeBrush()
  • DrawShape() //Here is our hook
  • ClearBrush()
  • Draw() is the template method

7
Example Continued
  • void RectangleDrawShape()
  • //Rectangle Drawing
  • //Implementation
  • The Rectangle subclass of Shape overrides
    DrawShape()

8
If You Only Remember One Thing
  • Template methods provide a means to develop a
    skeleton for an algorithm, making it an ideal and
    necessary method for code reuse.
  • Any Questions?

9
References
  • http//www.dofactory.com/Patterns/PatternTemplate.
    aspx
  • Design Patterns Elements of Reusable
    Object-Oriented Software by Gamma, Helm, Johnson
    and Vlissides
Write a Comment
User Comments (0)
About PowerShow.com