1 / 29

Lecture 29 : Template method Pattern

Computer Science 313 – Advanced Programming Topics. Lecture 29 : Template method Pattern. Professor. Professor Has A Problem. I need a cool assignment ,. Professor Has A Problem. I need a cool assignment , but my students only chug beer . API Coder Struggles With Design. How can I

sasson
Download Presentation

Lecture 29 : Template method Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 313 – Advanced Programming Topics Lecture 29:Template method Pattern

  2. Professor

  3. Professor Has A Problem I need a cool assignment,

  4. Professor Has A Problem I need a cool assignment, butmy students only chug beer

  5. API Coder Struggles With Design How can I write a component which coders can make look like their favorite Muppet?

  6. Owner Wants to Increase Sales I want to start selling hot drinks, but my McWorkers are idiots who cannot keep 2 ideas at a time.

  7. That Days Headline…

  8. What Do They Have in Common? • Each group member has single algorithm • Boil, Brew, Pour, & Serve for the Clown • Nerd must write Component & have Muppet drawn • One-handed, but cool, assignment for Professor • But these algorithms will be specialized • Completion of assignment left to the drunkards • Programmers will add Muppet drawings to API • Make coffee or tea based on order at McDs

  9. Therapist Provides a Suggestion This is complex. Perhaps a design pattern can help?

  10. To the Design Pattern Bin Design PatternsSlightly Used

  11. Rejecting the Design Patterns Strategy pattern sounds good, but I already have an algorithm.

  12. Rejecting the Design Patterns Observer pattern?Dude, the Component can only look like one Muppet at a time.

  13. Rejecting the Design Patterns Decorator pattern? You need to add new functionality!

  14. Rejecting the Design Patterns But how does that make you feel about your mother?

  15. Rejecting the Design Patterns If only Gilligan were here…

  16. Rejecting the Design Patterns …but this Abstract Factory gives me an idea.

  17. All About the Hooks • The Professor began to think • Never let a Professor think, it ends in bad places

  18. All About the Hooks • The Professor began to think • Never let a Professor think, it ends in bad places • Like this lecture…

  19. All About the Hooks • The Professor began to think • Never let a Professor think, it ends in bad places • He ends up wondering how velcro works

  20. All About the Hooks • The Professor began to think • Never let a Professor think, it ends in bad places • He ends up wondering how velcro works

  21. Template Method Pattern Key Yes! We only need to provide some hooks.

  22. Source of the Brain Storm • Velcro works by creating lots of little hooks • Loops on the connector then holds things up • Abstract factory method also creates hooks • Interface specifies methodsfor concrete factories • Clients create instances using these hooks • Subclasses create proper type for each method • How could they use this idea?

  23. Template Method Pattern • Superclass defines the steps of the algorithm • Specifies the single algorithm to implement • Creates abstract methods for missing details • Classes extend and complete superclass • Provide own copies of the abstract methods • Method defining algorithm inherited automatically • Client’s assume superclass is complete • Instances define details of the implementation

  24. Store Owner Increases Sales I define the process in an abstract superclassand rely on separate coffee & tea classes to define brewing step.

  25. API Writer Completes His Design I wrote my Component but left repaintMuppet abstract for users to define.

  26. API Writer Completes His Design Now I have to choose:Miss Piggy or Fozzy?

  27. Professor Has Cool Assignment

  28. Professor Has Cool Assignment But my studentsstill just want to chug beer

  29. For Next Class • Current lab due on Wednesday • Next cool lab assignment already on web • Means no lab over Spring Break • Next set of reports due Mon., April 12th • Read pages 287 – 298 for Wednesday • How do we implement the Template Method pattern? • Where have we used this before?

More Related