Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.

Slides:



Advertisements
Similar presentations
Using the Divide & Conquer Strategy to Teach Java Framework Design Conrad Cunningham, Yi Liu University of Mississippi Cuihua Zhang Northwest Vista College.
Advertisements

COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
Plab – Tirgul 12 Design Patterns
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
1 (More) Pattern Games CS : Software Design Winter /T10.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
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.
7/16/2015Singleton creational design pattern1 Eivind J. Nordby Karlstad University Dept. of Computer Science.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
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.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Strategy Design Patterns CS 590L - Sushil Puradkar.
Partitioning Patterns How to partition complex actors and concepts into multiple classes. Layered Initialization Filter Composite.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
CSC 480 Software Engineering Design With Patterns.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Design Patterns Introduction
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
CS 772: Global Knowledge Networks V. “Juggy” Jagannathan CSEE, West Virginia University Feb 18, 2002.
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.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 5150 Software Engineering Lecture 16 Program Design 3.
Session 30 Final Review. Final Details Wednesday, December 14 at 8 AM Wright 5 (same classroom) Final will be comprehensive Open book Open notes Test.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Design and implementation Chapter 7 – Lecture 1. Design and implementation Software design and implementation is the stage in the software engineering.
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.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Unit II-Chapter No. : 5- design Patterns
Strategy Design Pattern
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Presented by Igor Ivković
Software Engineering Lecture 7 - Design Patterns
CSC 480 Software Engineering
Advanced Java Programming
Software Design Lecture : 15.
Introduction to Design Patterns
CSC 480 Software Engineering
Presented by Igor Ivković
Software Design Lecture : 39.
Software Design Lecture : 28.
Chapter 5 Classes.
Presentation transcript:

Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes

Strategy Pattern This is a set of slides to accompany chapter 8 of Mark Grand’s book Patterns in Java : a catalog of reusable design patterns illustrated with UML (John Wiley & Sons, 1998) Created: 19 August 2004 Revised: 20 April 2010

Context Any one of a family of algorithms may do a task Wish to make then dynamically interchangeable  Invoke only operations on the base class  Delegate creation of the actual subclass object to a special class – factory 1

General Approach Common interface to family  abstract class/interface Encapsulate algorithm into implementing (sub)class Encapsulate algorithm into implementing (sub)class Delegate task by using interface 2

Example CalendarDisplay uses a Holiday instance to determine what holidays fall on each date Actually use instance of an appropriate subclass Composite Holiday further delegates to several other subclasses 3 CalendarDisplay Hoilday getHolidays(:Date):String[] Uses USHolidayCanadaHolidayCompostiteHoliday … 1..* Uses

Solution 4 Client ConcreteStrategy1 ConcreteStrategy2 … AbstractStrategy Operation() Uses A class in this role delegates an operation to an abstract class or interface. A class in this role provides common way to access operation encapsulated by its subclasses. Classes in this role implement alternative implementations of the operation that the client class delegate.

Consequences Client behavior dynamically determined object by object Client class simplified   No need to select/implement the alternative behavior Need way to configure 5

Example Code Client 6 class CalendarDisplay {private Holiday holiday; private static final String [] noHoliday = new String[0]; … // Private class used to cache information about dates private class DateCache { private Date date; private String[] holidayStrins; DateCache (Date dt) {date = dt; … if (holiday == null) holidayStrings = noHoliday; else HolidayStrings = holiday.getHolidays(date); … } // constructor(Date) }//class DateCache … } //class CalendatDisplay

Example Code AbstractStrategy public abstract class Holiday { protected final static String [] noHoliday = new String[0]; // Return array of strings describing holidays falling on a date // If no holidays fall on the given date, returns a zero length array abstract public String[] getHolidays(Date dt); }// class Holiday 7

Example Code ConcreteStrategy public class USHoliday extends Holiday { … public String [ ] getHolidays(Date dt) { String [ ] holidays = noHoliday; … return holidays; } //getHolidays(Date) } //class USHoliday 8

Acknowledgement 9 This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).” This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).”