Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nov 200391.3913 R McFadyen1 Strategy A strategy is a plan, or approach, for achieving an aim, given certain input conditions. Often strategies appear in.

Similar presentations


Presentation on theme: "Nov 200391.3913 R McFadyen1 Strategy A strategy is a plan, or approach, for achieving an aim, given certain input conditions. Often strategies appear in."— Presentation transcript:

1 Nov 200391.3913 R McFadyen1 Strategy 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

2 Nov 200391.3913 R McFadyen2 Strategy 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

3 Nov 200391.3913 R McFadyen3 Strategy 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

4 Nov 200391.3913 R McFadyen4 Textbook example > ISalePricingStrategy getTotal():Money PercentDiscount PicingStrategy percentage: float getTotal():Money AbsoluteDiscount OverThreshold PicingStrategy discount: Money threshold: Money getTotal():Money …

5 Nov 200391.3913 R McFadyen5 A strategy collaboration s: Sale:salesLineItem:PercentDiscount PricingStrategy getTotal() * : getSubTotal() getTotal(s)

6 Nov 200391.3913 R McFadyen6 How is the strategy object created? Usually, at most one object of each class is required … Use a factory

7 Nov 200391.3913 R McFadyen7 Strategy singleton : Sale ps:PercentDiscount PricingStrategy create() getSalePricingStrategy() create() > :PricingStrategyFactory In NextGenPOS, its possible to use a different strategy at any time … need code to replace the current strategy


Download ppt "Nov 200391.3913 R McFadyen1 Strategy A strategy is a plan, or approach, for achieving an aim, given certain input conditions. Often strategies appear in."

Similar presentations


Ads by Google