Presentation is loading. Please wait.

Presentation is loading. Please wait.

Template Methods Ordering What We Do. Example - Solitaire Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game.

Similar presentations


Presentation on theme: "Template Methods Ordering What We Do. Example - Solitaire Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game."— Presentation transcript:

1 Template Methods Ordering What We Do

2 Example - Solitaire Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game board Deal the cards onto the table Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game board Deal the cards onto the table

3 Options for building two solitaire games One class per game One class that defines the overall structure of a game and sub-classes for each particular game One class per game One class that defines the overall structure of a game and sub-classes for each particular game

4 Template for Solitaire

5 Template Method Defined The Template Method Pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. It lest subclasses redefine certain steps of an algorithm without changing the algorithm’s structure

6 Template Method Structure

7 Types of Methods in a Template Primitive Operations Abstract and left to subclasses for definition Concrete Operations Common for all subclasses, so concrete in the template class Hooks Default implementation in the Template class, but can be overridden by subclasses Usually do nothing if not overridden Primitive Operations Abstract and left to subclasses for definition Concrete Operations Common for all subclasses, so concrete in the template class Hooks Default implementation in the Template class, but can be overridden by subclasses Usually do nothing if not overridden

8 Look at Book’s Barista Example

9 Other Examples Equals Applets Hooks for init(), start(), stop(), … Book’s Pizza Factory Equals Applets Hooks for init(), start(), stop(), … Book’s Pizza Factory


Download ppt "Template Methods Ordering What We Do. Example - Solitaire Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game."

Similar presentations


Ads by Google