Strategy Design Pattern

Slides:



Advertisements
Similar presentations
GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Advertisements

Winter 2007ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Pattern – Bridge (Structural) References Yih-shoung Chen, Department of Information Engineering, Feng Chia University,Taiwan, R.O.C. The Bridge.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Spring 2010ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
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.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Strategy Design Patterns CS 590L - Sushil Puradkar.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
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.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
Stéphane Ducasse 1 Strategy.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CS 5150 Software Engineering Lecture 16 Program Design 3.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Examples (D. Schmidt et al)
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Strategy: A Behavioral Design Pattern
Abstract Factory Pattern
Design Patterns: Brief Examples
Factory Method Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 10 Design Patterns.
Software Design Patterns
Factory Patterns 1.
Introduction to Design Patterns
Behavioral Design Patterns
Software Design and Architecture
Flyweight Design Pattern
Factory Method Pattern
object oriented Principles of software design
Abstract Factory Pattern
Presented by Igor Ivković
Object Oriented Analysis and Design
State Design Pattern 1.
Mediator Design Pattern (Behavioral)
Chapter 22 Object-Oriented Design
DESIGNING YOUR SYSTEM.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Software Design Lecture : 14.
DESIGN PATTERNS : Strategy Pattern
Design pattern Lecture 9.
Strategy and Template Method Patterns, Single User Protection
Strategy Design Pattern
Design Patterns (Gamma, Helm, Johnson, Vlissides)
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Strategy Design Pattern EECS 6431- Software Re-engineering Nasim Razavi

Table of Content Strategy pattern Motivation Intent Applicability Structure Participants Implementation Sequence diagram Consequences References

Strategy pattern Strategy pattern (known as policy) is a behavioral software design pattern that enables a behavior (an algorithm) to be selected at runtime. A Strategy defines a set of algorithms that can be used interchangeably.

Motivation A superclass or an interface may offer features that are not applicable for all subclass. In this case, for instance, we have to overwrite those features for some subclasses. Having optional features in the supper classes that are only relevant to some subclasses causes many duplicate codes and long lists of conditionals. A class have different behaviors. Multiple algorithms can be implemented for a specific task.

Motivation Example

Intent The behavior of a class to be independent from the clients that use it. By encapsulating each algorithm and make them interchangeable. Put the abstraction in an interface, push implementation details down to derived classes. The behavior can change in subclasses without side effects.

Applicability Use the Strategy pattern when Many related classes differ only in their behavior. To avoid complex code. We have multiple algorithms for a specific task and we want the client decides what strategy to be used at runtime.

Structure

Participants Strategy ConcreteStrategy Context Client Declares an interface common to all supported algorithms. Different behaviors can be selected by swapping between ConcreteStrategys without any side effect in Context. ConcreteStrategy Defines an algorithm by implementing the Strategy interface. Context Is composed of a strategy. It is a class that requires changing behaviors. Client Defines what behavior the context uses.

Implementation Define the Strategy and Context. Make Strategy objects of related algorithms. The strategies can be defined as a hierarchy of classes offering the ability to extend and customize the existing algorithms. The context object can have a default algorithm. In runtime, if it does not contain a strategy object, it will execute the default algorithm.

Sequence Diagram

Example

Consequences Benefits Encapsulates families of related algorithms into Strategy classes. Keeps class changes from forcing other class changes. Implements algorithms independent from the Context class. Simplifies switching, understanding, and extending the algorithms. Avoids duplicate codes. Eliminates conditional statements. Is flexible. The client can choose among different strategies.

Consequences Drawbacks Communication overhead between Strategy and Context. The increased number of objects. The client has to be aware of strategies and their difference.

Refrences Vlissides, John, et al. "Design patterns: Elements of reusable object-oriented software." Reading: Addison-Wesley 49.120 (1995): 11.