Strategy Pattern.

Slides:



Advertisements
Similar presentations
Creational Patterns (2) CS350/SE310 Fall, Lower the Cost of Maintenance Economic Goal Coupling-Cohesion, Open-Close, Information-Hiding, Dependency.
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.
+ Informatics 122 Software Design II Lecture 7 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
The Strategy Pattern CSC 211: Design Patterns. Reading Quiz.
Informatics 122 Software Design II
Strategy Pattern1 Design Patterns 1.Strategy Pattern How to design for flexibility?
Computer Science 313 – Advanced Programming Topics.
Inheritance issues SE-2811 Dr. Mark L. Hornick 1.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Strategy AKA Policy Dale Willey Ian Price. Overview Definitions Difference between Strategy pattern and strategy Where would you use this? Challenges.
STRATEGY Object Behavioral Pattern. You are at the Pub two weeks before Fall Formal and still don’t have a date! All of a sudden a girl who you had a.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
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.
COMP 121 Week 02. Agenda Review this week’s expected outcomesReview this week’s expected outcomes Review Guided Learning Activity solutionsReview Guided.
DAAD project “Joint Course on OOP using Java” Design Patterns in the course ‘OOP in Java’ - first experiences Ana Madevska Bogdanova Institute of informatics.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
CS 210 Introduction to Design Patterns September 28 th, 2006.
Case Studies on Design Patterns Design Refinements Examples.
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
Strategy Design Patterns CS 590L - Sushil Puradkar.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1 Class 1-2.
SE-2811 Software Component Design Week 1, Day 2 (and 1-3 and 2-1) SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS 210 Introduction to Design Patterns August 29, 2006.
The Strategy Design Pattern © Allan C. Milne v
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.
CS 210 Review October 3, 2006.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
It started with a simple … A highly successful duck pond simulation game called SimUDuck The game can show a large variety of duck swimming and making.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Systems Requirements SE 3821 Design? Algorithms CS 2852.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
SE 461 Software Patterns Welcome to Design Patterns.
Intro to Design Pattern
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Design Patterns Lecture part 2.
CS 350 – Software Design The Strategy Pattern – Chapter 9
Chapter Nine The Strategy Pattern
Behavioral Design Patterns
Software Design and Architecture
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
object oriented Principles of software design
Strategy Design Pattern
Presented by Igor Ivković
SE-2811 Software Component Design
State Design Pattern 1.
Object-Oriented Programming
SE-2811 Software Component Design
Design pattern Lecture 9.
Strategy Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Design Patterns Lecture part 1.
Informatics 122 Software Design II
Presented by Igor Ivković
Software Design Lecture : 27.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Strategy Pattern

Strategy Pattern Intent Also known as “Policy” Motivating example Define a family of algorithms, encapsulate each one,and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Also known as “Policy” Motivating example Different line break algorithms for varying types of text

SimUDuck example Joe works for a company that makes a highly successful duck pond simulation game, SimUDuck. The game can show a large variety of duck species swimming and making quacking sounds.

Inheritance based design

Inheritance based design Now RubberDuck can fly!

What about using Interface?

What about using Interface? Duplicated code! Now try changing fly().

Encapsulate Behaviors Separate them out of the client Define as interfaces

Delegate behaviors

Strategy Pattern

Design Principles Identify the aspects of your application that vary and separate them from what stays the same. Program to an interface, not an implementation. Favor composition over inheritance Has-A is better than Is-A

Strategy Pattern in FP Different strategies are just different functions Higher order functions (HOF) Function is first -class, can live alone and be passed around In OOP, method is not first-class, must be encapsulated in a class (“world of nouns”)

What about polymorphism? Dispatch on type Calling different functions according to the data type In Clojure Custom data type: defrecord Custom behavior groups (interface): defprotocol Don't support inheritance