Strategy: A Behavioral Design Pattern

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Case Studies on Design Patterns Design Refinements Examples.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
 How are you going to collaborate?  How are you going to divide up work?  How are you going to make sure that changes work with other people’s code?
Strategy Design Patterns CS 590L - Sushil Puradkar.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
OO Methodology Elaboration Iteration 2 - Design Patterns -
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Patterns References: Xiaoping Jia, Object-Oriented Software Development Using Java;Douglas C.Schmidt, Design Pattern Case Studies with C++
STRATEGY PATTERN. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
Stéphane Ducasse 1 Strategy.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
By SmartBoard Team. Agenda  Scenario & Writing UML  Discuss with each team’s UML  What if…  BMVV design  Strategy pattern  Applied with BMVV design.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Patterns: Brief Examples
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 10 Design Patterns.
Software Design Patterns
Design Patterns Lecture part 2.
Factory Patterns 1.
Introduction to Design Patterns
Behavioral Design Patterns
Abstract Factory Pattern
State Design Pattern 1.
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
DESIGN PATTERNS : Strategy Pattern
DESIGN PATTERNS : State Pattern
Design pattern Lecture 9.
Strategy and Template Method Patterns, Single User Protection
State Design Pattern Brandon Jacobsen.
Strategy Design Pattern
Informatics 122 Software Design II
Design by Abstraction (Continuation) CS 3331 Spring 2005
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Strategy: A Behavioral Design Pattern By Anne Ryan

What is a Design Pattern? A design pattern deals with interactions between individual software components They are recurring solutions to common problems of design!

Types of Design Patterns Creational Structural Behavorial Strategy is a behavioral design pattern

Strategy In a Strategy design pattern, you will: Define a family of algorithms Encapsulate each one Make them interchangeable

You should use Strategy when: You have code with a lot of algorithms You want to use these algorithms at different times You have algorithm(s) that use data the client should not know about

Strategy Class Diagram Context contextInterface() Strategy algorithmInterface() ConcreteStrategyA algorithmInterface() ConcreteStrategyB algorithmInterface() ConcreteStrategyC algorithmInterface()

Strategy vs. Subclassing Strategy can be used in place of subclassing Strategy is more dynamic Multiple strategies can be mixed in any combination where subclassing would be difficult

Subclassing Class functionX() SubClass1 SubClass2 SubClass3

Add a function Class SubClass1 SubClass2 SubClass3 Add functionY() functionX() functionY() SubClass1 functionX() SubClass2 SubClass3 Add functionY()

What happens? Class Need SIX classes to handle both functions!!! functionX() functionY() Need SIX classes to handle both functions!!! SubClass1 functionX() functionY() SubClass2 functionX() functionY() SubClass3 functionrX() functionY() SubClass2.1 behaviorY() SubClass2.2 behaviorY()

Strategy makes this easy! StrategyX functionX() ... Class functionX() functionY() StrategyY functionY() ...

Benefits of Strategy Eliminates conditional statements Can be more efficient than case statements Choice of implementation Client can choose among different implementations with different space and time trade-offs

Benefits of Strategy Families of related algorithms Alternative to subclassing This lets you vary the algorithm dynamically, which makes it easier to change and extend You also avoid complex inheritance structures

Drawbacks of Strategy Clients must be aware of different strategies Clients must know how strategies differ so it can select the appropriate one Communication overhead between strategy and context Sometimes the context will create and initialize parameters that are never used

Drawbacks of Strategy Increased number of objects if the algorithm differences are simple, the extra classes add extra complexity

Implementation Issues Context contextInterface() Strategy algorithmInterface() ConcreteStrategyA algorithmInterface() ConcreteStrategyB algorithmInterface() ConcreteStrategyC algorithmInterface()

Implementation Issues Concrete Strategy needs efficient access to data Should you use a template? Should you make strategy objects optional?

Thank you to Provider of the PowerPoint graphs: http://vik.ktu.lt/moduliai/

What have we learned today about strategy?