Chapter Nine The Strategy Pattern

Slides:



Advertisements
Similar presentations
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Advertisements

The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Computer Science 313 – Advanced Programming Topics.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Programming by evolution Y C Cheng Associate Professor Department of Computer Science and Information Engineering National Taipei University of Technology.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
Reuse Activities Selecting Design Patterns and Components
Chapter 22 Object-Oriented Design
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
DAAD project “Joint Course on OOP using Java” Design Patterns in the course ‘OOP in Java’ - first experiences Ana Madevska Bogdanova Institute of informatics.
1 Pattern-Oriented Design by Rick Mercer based on the GoF book and Design Patterns Explained A New Perspective on Object-Oriented Design Alan Shalloway,
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Case Studies on Design Patterns Design Refinements Examples.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
CS 4240: More Design Patterns Readings: Chap. 9. Let’s Recap Some Ideas and Strategies We’ll assume some design-planning is useful up-front Design with.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
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.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
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.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Chapter 18 The Observer Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Chapter 21 Design Patterns Reviewed from the New Perspective of Object-Oriented Design Ku-Yaw Chang Assistant Professor, Department.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
Chapter 19: Interfaces and Components [Arlow and Neustadt, 2005] University of Nevada, Reno Department of Computer Science & Engineering.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
CS 210 Introduction to Design Patterns August 29, 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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
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.
CS 210 Introduction to Design Patterns September 14 th, 2006.
Examples (D. Schmidt et al)
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
CompSci 280 S Introduction to Software Development
Software Design Refinement Using Design Patterns
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Strategy Pattern.
Chapter Six The Facade Pattern
CS 350 – Software Design The Strategy Pattern – Chapter 9
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Instructor: Dr. Hany H. Ammar
Chapter 19: Interfaces and Components
State Design Pattern 1.
Informatics 122 Software Design II
Pattern-Oriented Design
Chapter 19: Interfaces and Components
Chapter 19: Interfaces and Components
DESIGN PATTERNS : Strategy Pattern
DESIGN PATTERNS : State Pattern
CS 350 – Software Design Principles and Strategies – Chapter 14
Strategy Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
System Reengineering Restructuring or rewriting part or all of a system without changing its functionality Applicable when some (but not all) subsystems.
Chapter 10 Thinking in Objects Part 1
Presented by Igor Ivković
Interfaces and Components
Chapter 19: Interfaces and Components
GoF Patterns Ch. 26.
Presentation transcript:

Chapter Nine The Strategy Pattern Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

Overview A new case study The problem of new requirements e-commerce A solution using the Strategy pattern The problem of new requirements Approaches to handling new variations Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

An Approach to Handling New Requirements Disaster often comes in the long run from suboptimal decisions in the short run. Desktop filing system Software development are concerned With handling immediate, pressing needs Without future maintenance Management is under pressured to deliver, not to maintain Ku-Yaw Chang The Strategy Pattern

An Approach to Handling New Requirements Design for change Program to an interface, not an implementation Favor object [aggregation] over class inheritance Consider what should be variable in your design. The opposite of focusing on the cause of redesign Encapsulate the concept that varies Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

International E-Commerce System An order-processing system for an international e-commerce company in the U.S. To process sales orders in many different countries General architecture A controller object Handles sales requests A SalesOrder To process the order Ku-Yaw Chang The Strategy Pattern

International E-Commerce System Functions of SalesOrder Allow for filling out the order with a GUI Handle tax calculations Process the order, and print a sales receipt Be implemented with the help of other objects SalesTicket object that prints the SalesOrder Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Handle taxes on orders from customers outside the U.S. Available approaches Copy and paste Switches or ifs on a variable Use function pointers or delegates Inheritance Delegate the entire functionality to a new object Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Switches Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Switches Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Switches Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Inheritance Handle Germany or get other things that are varying Tall inheritance hierarchies result from specialization techniques Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Design patterns take a different approach Consider what should be variable in your design Encapsulate the concept that varies Favor object-aggregation over class inheritance Do the following Find what varies and encapsulate it in a class of its own Contain this class in another class Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Step 1 Find what varies and encapsulate it A CalcTax object defines the interface Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Step 2 Favor aggregation One SalesOrder class contains the CalcTax class to handle the variations Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Advantages Better cohesion More flexible Easier to shift responsibilities Ku-Yaw Chang The Strategy Pattern

Handling New Requirements Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

The Strategy Pattern Intent Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Ku-Yaw Chang The Strategy Pattern

The Strategy Pattern Principles Objects have responsibilities. Different, specific implementations of these responsibilities are manifested through the use of polymorphism. There is a need to manage several different implementations of what is, conceptually, the same algorithm. Ku-Yaw Chang The Strategy Pattern

Generic Structure Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

Using the Strategy Pattern Encapsulating business rules More than algorithms Coupling between context and strategies Required information Passed to strategies Lowers cost of unit tests Ku-Yaw Chang The Strategy Pattern

Outline Overview An Approach to Handling New Requirements The International E-Commerce System Case Study: Initial Requirements Handling New Requirements The Strategy Pattern Field Notes: Using the Strategy Pattern Summary Ku-Yaw Chang The Strategy Pattern

Summary A way to define a family of algorithms Do the same things Have different implementations Ku-Yaw Chang The Strategy Pattern

The End