Template Method Pattern

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Template Method Pattern - Presentation Transcript

    1. Template Method Pattern High Level Algorithm Monis Iqbal Snr. Software Engineer Creative Chaos (pvt.) Limited
    2. Definition
      • 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. <GOF>
      • Different implementations of algorithms leading to different algorithm altogether. (Similar code maintained differently)
      • Every class requires full knowledge of the algorithm.
      • Code duplication (Yuc!!)
      • Algorithm encapsulated in single class
      • Single control/entry point.
      • Subclasses only need to provide specialized algorithm details.
    3.  
    4. Primitive Methods
      • Abstract class declares primitive methods leaving the subclasses to provide functionality.
      • Primitive methods used in Template Method .
      • Nicely documented and meaningfully named.
    5. Concrete methods
      • Used in Template method
      • Defined in abstract class
      • Declared final
    6. Hooks
      • Hook placed in the Template method.
      • Abstract class provides implementation.
      • Subclasses can “hook into” the algorithm if they want.
      • abstract class AbstractClass {
      • final void templateMethod() {
      • primitiveOperation1();
      • primitiveOperation2();
      • concreteOperation();
      • if (hookIsTrue())
      • hook();
      • }
      • abstract void primitiveOperation1();
      • abstract void primitiveOperation2();
      • void final concreteOperation() {
      • … ..
      • }
      • boolean hookIsTrue() { return false; }
      • void hook() {}
      • }
    7. Cache revisited
      • Example by Code
        • First in First Out (FIFO) Cache
        • Least Recently Used (LRU) Cache
    8. Intuition
      • Encapsulation of Algorithm
      • Don’t call us, we’ll call you. (Hollywood Principle).
    9. Questions ???

    + monisiqbalmonisiqbal, 8 months ago

    custom

    506 views, 0 favs, 4 embeds more stats

    Template Method Pattern (TMA)

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 506
      • 474 on SlideShare
      • 32 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 13
    Most viewed embeds
    • 28 views on http://monisiqbal.blogspot.com
    • 2 views on http://www.blogger.com
    • 1 views on http://www.monisiqbal.blogspot.com
    • 1 views on http://scriptconv.appspot.com

    more

    All embeds
    • 28 views on http://monisiqbal.blogspot.com
    • 2 views on http://www.blogger.com
    • 1 views on http://www.monisiqbal.blogspot.com
    • 1 views on http://scriptconv.appspot.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories