Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2009ACS-3913 R McFadyen1 GoF Patterns, chapter 26 GoF book presents 23 patterns: Creational – 5 Structural – 7 Behavioural – 11 Larman discusses 7.

Similar presentations


Presentation on theme: "Fall 2009ACS-3913 R McFadyen1 GoF Patterns, chapter 26 GoF book presents 23 patterns: Creational – 5 Structural – 7 Behavioural – 11 Larman discusses 7."— Presentation transcript:

1 Fall 2009ACS-3913 R McFadyen1 GoF Patterns, chapter 26 GoF book presents 23 patterns: Creational – 5 Structural – 7 Behavioural – 11 Larman discusses 7 Many texts cover the GoF patterns, examples: Java design patterns; James Cooper Head First Design Patterns; Freeman & Freeman Design patterns explained; Shalloway & Trott Object-oriented design & patterns; Horstmann …

2 Fall 2009ACS-3913 R McFadyen2 GoF Patterns, chapter 26 Some web sites Data & Object Factory http://dofactory.com/Patterns/Patterns.aspx http://dofactory.com/Patterns/Patterns.aspx Allen Holub http://www.holub.com/http://www.holub.com/ Showing pattern collaborations http://www.holub.com/goodies/patterns/GameOfLife Models.pdf http://www.holub.com/goodies/patterns/GameOfLife Models.pdf

3 Fall 2009ACS-3913 R McFadyen3 A strategy is a plan, or approach, for achieving an aim, given certain input conditions. Often strategies appear in groups or families When multiple strategies are available, the logic to select one may be complicated. We can clean up such code with Strategy Strategy

4 Fall 2009ACS-3913 R McFadyen4 Create an interface to define the strategic operation Implement the interface with classes that represent each strategy These classes contain the strategy code We need to determine which strategy to apply The choice of which strategy to apply could be handled by a strategy factory Using strategy

5 Fall 2009ACS-3913 R McFadyen5 In the text, they want to be able to use varying pricing strategies for sales. Strategies such as Give a discount if sales are over … Always give a discount of … Give frequent customers a discount … The strategy in effect will vary … This is a point of variation in the system … and we want the system to be flexible Having several pricing strategies

6 Fall 2009ACS-3913 R McFadyen6 Textbook example > ISalePricingStrategy getTotal():Money PercentDiscount PicingStrategy percentage: float getTotal():Money AbsoluteDiscount OverThreshold PicingStrategy discount: Money threshold: Money getTotal():Money … Sale

7 Fall 2009ACS-3913 R McFadyen7 A strategy collaboration s: Sale:salesLineItem[i]:PercentDiscount PricingStrategy getTotal() * : getSubTotal() getTotal(s)

8 Fall 2009ACS-3913 R McFadyen8 How is the strategy object created? Usually, at most one object of each class is required … Use a factory

9 Fall 2009ACS-3913 R McFadyen9 Strategy singleton : Sale ps:PercentDiscount PricingStrategy new() getSalePricingStrategy() new() > :PricingStrategyFactory In NextGenPOS, its possible to use a different strategy at any time … need code to replace the current strategy


Download ppt "Fall 2009ACS-3913 R McFadyen1 GoF Patterns, chapter 26 GoF book presents 23 patterns: Creational – 5 Structural – 7 Behavioural – 11 Larman discusses 7."

Similar presentations


Ads by Google