SlideServe
Menu
Préférences
© SlideServe · v2026

Lecture 29: Template method Pattern

adelie avatar
29 diapositives · 445 Views · Jul 10, 2014

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 (& other things I do not want to think about).

Lecture 29: Template method Pattern - slide 1
01 / 29Lecture 29: Template method Pattern
1 / 17

Télécharger la présentation

Lecture 29: Template method Pattern
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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 (& other things I do not want to think about)

  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 • Assignment for non-beer (etc.) hand for Professor • But these algorithms will be specialized • Completion of assignment left to chemically-altereds • 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 studentsnow looking for their (beer) bong

  29. For Next Class • Remember the lab due before next Friday • No lab this week, so get extra time to complete • Read pages 287 – 298 for Wednesday • How do we implement the Template Method pattern? • Where have you seen this before?