strategy

14
Strategy Pattern Shahriar Iqbal Chowdhury Monjurul Habib Code Name: Remington http://www.facebook.com/groups/netter/

Upload: monjurul-habib

Post on 05-Jul-2015

126 views

Category:

Technology


0 download

DESCRIPTION

1. Strategy Pattern Shahriar Iqbal Chowdhury Monjurul Habib Code Name: Remington http://www.facebook.com/groups/netter/ 2. What is StrategyA plan of action or policy designed to achieve a major or overall aim. 3. Why Need Pattern for Strategy• The Strategy pattern is known as a behavioural pattern - its used to manage algorithms, relationships and responsibilities between objects.• The Strategy pattern is to be used where you want to choose the algorithm to use at runtime. A good use of the Strategy pattern would be saving files in different formats, running various sorting algorithms, or file compression 4. Strategy Pattern Says• Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it OR 5. Why, When and How?1. Allow a class to maintain a single purpose.2. Switch statement3. Adding a new implementation will cause a class file to be modified4. Create a class for each strategy5. Use a common interface for each strategy 6. Class Diagram 7. Pattern less Implementation 8. Context IStrategy 9. Concrete Strategy UPS Concrete Strategy USPS 10. WALL-E & Strategy Strategy : Capable to Identify Object Strategy : Identify and Recycle Garbage 11. Strategy : Identify Friend Strategy : Identify Girl Friend  12. Strategy : Identify New Hope For Mankind 13. Strategy @.Net Framework• Array and ArrayList provide the capability to sort. Sort method will use the IComparable implementation for each element to handle the comparisons. Leaving the choice of comparison algorithm up to the user of the class like this is an example of the Strategy pattern.• The use of a Predicate delegate in the FindAll method lets the caller use any method as a filter for the List so long as it takes the appropriate object type and returns a Boolean.

TRANSCRIPT

Page 1: Strategy

Strategy PatternShahriar Iqbal Chowdhury

Monjurul Habib

Code Name: Remington

http://www.facebook.com/groups/netter/

Page 2: Strategy

What is Strategy

A plan of action or policy designed to achieve a major or overall aim.

Page 3: Strategy

Why Need Pattern for Strategy

• The Strategy pattern is known as a behavioural pattern - it's used to manage algorithms, relationships and responsibilities between objects.

• The Strategy pattern is to be used where you want to choose the algorithm to use at runtime. A good use of the Strategy pattern would be saving files in different formats, running various sorting algorithms, or file compression

Page 4: Strategy

Strategy Pattern Says

• Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it

OR

Page 5: Strategy

Why, When and How?

1. Allow a class to maintain a single purpose.

2. Switch statement

3. Adding a new implementation will cause a class file to be modified

4. Create a class for each strategy

5. Use a common interface for each strategy

Page 6: Strategy

Class Diagram

Page 7: Strategy

Pattern less Implementation

Page 8: Strategy

Context IStrategy

Page 9: Strategy

Concrete Strategy UPS Concrete Strategy USPS

Page 10: Strategy

WALL-E & Strategy

Strategy : Identify and Recycle Garbage

Strategy : Capable to Identify Object

Page 11: Strategy

Strategy : Identify Friend Strategy : Identify Girl Friend

Page 12: Strategy

Strategy : Identify New Hope For Mankind

Page 13: Strategy

Strategy @.Net Framework

• Array and ArrayList provide the capability to sort. Sort method will use the IComparable implementation for each element to handle the comparisons. Leaving the choice of comparison algorithm up to the user of the class like this is an example of the Strategy pattern.

• The use of a Predicate<T> delegate in the FindAll<T> method lets the caller use any method as a filter for the List<T> so long as it takes the appropriate object type and returns a Boolean.

Page 14: Strategy

That’s It!!