21 Pages

CS 350 - Chapter9

Course: CS 350, Fall 2009
School: Drexel
Rating:
 
 
 
 
 

Word Count: 1153

Document Preview

350 CS Software Design The Strategy Pattern Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore the longer term. Two common approaches: Overanalyze and overdesign: Analysis paralysis Jump right in Somewhere in between is the ideal. This is why I feel the argument in Software Engineering about Agile methodologies vs. traditional waterfall development is...

Register Now

Unformatted Document Excerpt

Coursehero >> Pennsylvania >> Drexel >> CS 350

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
350 CS Software Design The Strategy Pattern Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore the longer term. Two common approaches: Overanalyze and overdesign: Analysis paralysis Jump right in Somewhere in between is the ideal. This is why I feel the argument in Software Engineering about Agile methodologies vs. traditional waterfall development is silly. It should always be a combination. In addition, a key element is to be wise enough to DESIGN FOR CHANGE. Simple to say, no so intuitive (at first) to do. With practice, its not that difficult. CS 350 Software Design The Strategy Pattern Chapter 9 We do not anticipate the exact change, instead we anticipate what may change. New Case Study: E-Commerce System The company is located in the US, but its business has an international scope A Task controller object handles sales request and passes it to the SalesOrder object to process the order. CS 350 Software Design The Strategy Pattern Chapter 9 The functions for SalesOrder include the following: Allow for filling out the order with a GUI Handle tax calculations Process the order and print a sales receipt Some object will be implemented with the help of other objects SalesOrder will not print itself CS 350 Software Design The Strategy Pattern Chapter 9 What happens when requirements change? Perhaps a new requirement for taxation rules is added. Handle taxation for countries outside the United States. Thus, we need to add new rules for computing taxes. CS 350 Software Design The Strategy Pattern Chapter 9 How do we handle different implementations of tasks that are pretty much conceptually the same? Copy and paste Switches/Ifs on variable specifying the case we have Use function pointers (a different one representing each case) Inheritance Delegate the entire functionality to a new object CS 350 Software Design The Strategy Pattern Chapter 9 Copy / Paste Traditional method Copy something that works, paste it somewhere else, make a changes. Maintenance headaches Switches Issues with coupling, testing More importantly, what happens when you have multiple variations? CS 350 Software Design The Strategy Pattern Chapter 9 Simple Cases Two Countries // Handle Tax switch (myNation) { (myNation) case US: //US Tax Rules here break; case Canada: //Canadian Tax Rules here break; } //Handle Currency switch (myNation) { (myNation) case US: //US Currency Rules here break; case Canada: //Canadian Currency Rules here break; } //Handle Date Format switch (myNation) { (myNation) case US: //US Date Format Rules here break; case Canada: //Canadian Date Format Rules here break; } CS 350 Software Design The Strategy Pattern Chapter 9 Add a Third Country Still a Clean implementation // Handle Tax switch (myNation) { (myNation) case US: //US Tax Rules here break; case Canada: //Canadian Tax Rules here break; case Germany: //Germany Tax Rules here break; } //Handle Currency switch (myNation) { (myNation) case US: //US Currency Rules here break; case Canada: //Canadian Currency Rules here break; case Germany: //Germany Currency Rules here break; } CS 350 Software Design The Strategy Pattern Chapter 9 Add a Third Country Still a Clean implementation You may need to add another switch // Handle Language switch (myNation) { (myNation) case US: case Canada: //use English break; case Germany: //use German break; } CS 350 Software Design The Strategy Pattern Chapter 9 Variations dirty the implementation // Handle Language switch (myNation) { (myNation) case Canada: if (inQuebec) { (inQuebec) //use French break;} else //use English break; case Germany: //use German break; } Flow of the switches is hard to read When new cases come in, you must find every place it can be involved Called Switch Creep CS 350 Software Design The Strategy Pattern Chapter 9 Function Pointers Nice Compact Cant retain state on a per-object Inheritance basis Nothing really wrong with it per say Certainly allows reuse Could create new SalesOrder objects from existing objects CS 350 Software Design The Strategy Pattern Chapter 9 Inheritance What happens when things vary independently? Too many classes! Thing of the German example where we may vary data format, language, and freight rules CS 350 Software Design The Strategy Pattern Chapter 9 A Better Approach 1. Find out what varies and encapsulate it in a class of its own. 2. Contain this class in another class. What varies in this example? Tax rules, therefore create an abstract class that defines how to accomplish taxation conceptually. CS 350 Software Design The Strategy Pattern Chapter 9 A Better Approach Now use aggregation to give the SalesOrder object the ability to handle Tax. CS 350 Software Design The Strategy Pattern Chapter 9 public abstract class CalcTax { abstract public double taxAmount(long itemSold, double price); } itemSold, Public class CanTax extends CalcTax { public double TaxAmount (long itemSold, double price){ itemSold, //in real life, figure out tax according to the rules in Canada and return it Canada //here return 0 so this will compile return 0.0; } } Public class USTax extends CalcTax { public double TaxAmount (long itemSold, double price){ itemSold, //in real life, figure out tax according to the rules in the US and return it the //here return 0 so this will compile return 0.0; } } CS 350 Software Design The Strategy Pattern Chapter 9 public class SalesOrder { public void process (CalcTax taxToUse) { (CalcTax taxToUse) long itemNumber=0; itemNumber=0; double price=0; //given the tax object to use, calculate the tax double tax = taxToUse.taxAmount(itemNumber, price); taxToUse.taxAmount(itemNumber, } } public class TaskController { public void process() { // this code is an emulation of a processing task controller controller // figure out what country you are in CalcTax myTax; myTax; myTax = getTaxRulesForCountry(); getTaxRulesForCountry(); SalesOrder mySO = new SalesOrder(); SalesOrder(); mySO.process(myTax); mySO.process(myTax); } CS 350 Software Design The Strategy Pattern Chapter 9 A Better Approach CS 350 Software Design The Strategy Pattern Chapter 9 So Whats the Difference? Looking at it quickly, it appears we just pushed the problem down the chain. The...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Cornell - DEA - 3500
Professor Alan Hedge,Cornell University, January 2008Indoor Air Quality: Gases, vapors, particles and fibers.DEA 350 Human Factors - Ambient EnvironmentIndoor Air PollutantsParticles or gases that occur in the air inside buildings that have an adver
NYU - DOCS - 10195
DEPARTMENTS OF BIOCHEMISTRY/CHEMISTRY JOINT SEMINARPlease PostChemical Approaches to Sorting out Histone-Modifying Enzymes Philip A. Cole, M.D., Ph.D.Johns Hopkins University Department of Pharmacology Director and E.K. Marshall and Thomas H. Maren Pro
Rose-Hulman - ES - 201
NameSectionES201 Examination I December 19, 1997Problem 1 2 3 4 TotalScore /20 /20 /30 /30 /100Show all work for credit (system, principle, etc.) AND Turn in your signed help sheet And Remain in your seat for the entire examName ES201 Examination I
Bowling Green - EDHD - 633
APA BIBLIOGRAPHIC REFERENCINGJOURNAL ARTICLE: Klimoski, R., & Palmer, S. (1993). The ADA and the hiring process in organizations: Policies and benefits. Consulting Psychology Journal: Practice and Research, 45 (2), 10-36.Note 1: Capitalize only the firs
Clarkson - ME - 341
Fracture Mechanics OverviewME341 Carl Hooverbud21932_0522.jpgElliptical "Crack"bud21932_0523.jpgCrack Modes: Tension, Shear, Tearingbud21932_0524.jpgMode 1 Infinite Plate w/ Crack Can estimate stress around crack tipStress Intensity Factor: Mode
SUNY Stony Brook - CSE - 594
The Essential Element for MRI: HydrogenIntroduction to Medical Imaging Lecture 11: MRI PhysicsIn MRI only hydrogen is used for imaging: 1H the hydrogen atom is a component of water: H20 the body consists of 2/3 water a lot of potential signal The hydrog
UMass (Amherst) - HIST - 180
Mon. 9/18Announcements If your name is not on the attendance sheet today, please see me after class. Your announcementsFrom agriculture to civilizationPristine civilizations Hydraulic hypothesis Environmental circumscription Diffusion or independent in
Washington University in St. Louis - CSE - 522
Introduction to RealTime SystemsFred KuhnsApplied Research Laboratory Department of Computer Science and Engineering Washington University in St. Louis(fredk@arl.wustl.edu, http:/www.arl.wustl.edu/~fredk)WASHINGTON UNIVERSITY IN ST LOUISWashingtonWh
Purdue - CE - 697
Special Plate Shear Walls History: Research and Applications Mechanics of slender-web shear walls Design of Steel Plate Shear Walls AISC Seismic Provisions for Special Plate Shear Walls (SPSW)Low Yield Strength (LYS) Panels For common plate material
Arkansas State - MIS - 3353
CIT 3353 Fall 2006 www.clt.astate.edu/jseydel/mis3353Website Development & ManagementGetting to Know HTML BetterInstructor: John Seydel, Ph.D. Student ObjectivesUpon completion of this class meeting, you should be able to:Explain the major elements
Cornell - MATH - 293
Math 293 Solutions to Problem Set 8. Here are just the answers to the even-numbered problems. The answers to odd-numbered problems are in the book. More complete solutions will be posted after the problem sets are turned in. 4.7 #4. The general solution i
MIT - MAS - 961
COVER FEATURESmart Dust: Communicating with a CubicMillimeter ComputerThe Smart Dust project is probing microfabrication technology's limitations to determine whether an autonomous sensing, computing, and communication system can be packed into a cubic-
Sanford-Brown Institute - CSCI - 1900
Dominic Latty January 31, 2007 CS 190RequirementsI. Intuitive system that, given a book's call number, can retrieve a map highlighting the area of the shelf where the book is located. A. The system would read in the book's call number by parsing HTML co
Portland - CECS - 386
Introduction to DatabasesWeek 1, April 4/6, 2006Instructor:David Maier maier@cs.pdx.edu Nick Rayner raynern@cecs.pdx.eduTA:Class e-mail list: cs386@cs.pdx.edu URGENT! In order to join the mail list, please visit the following web page and register: h
Oregon State University - PH - 585
VOLUME 82, NUMBER 4PHYSICAL REVIEW LETTERS25 JANUARY 1999High Precision Measurements of the Ground State Hyperne Structure Interval of Muonium and of the Muon Magnetic MomentW. Liu,1 M. G. Boshier,1 S. Dhawan,1 O. van Dyck,2 P. Egan,3 X. Fei,1 M. Gros
CSU Sacramento - EDS - 100
Essentials of Universal Design Seven Principles of Universal Design 1. The design can be used by, and marketed to, all kinds of people. A good example is power doors which open automatically when someone steps on a pressuresensitive area on the pathway le
Duke - CPS - 296
CPS296.2 Geometric OptimizationJanuary 18, 2007Lecture 3: Interior Point Methods and Meggidos AlgorithmLecturer: Pankaj K. Agarwal Scribe: Jen Burge3.1Interior Point MethodsSo far the two methods we have studied for solving linear programs were the
UMass (Amherst) - NRC - 297
GeoreferencingSlides for this presentation were developed by Charles SchweikSpatial data include coordinates defining location, shape and extent of geographic objects. To use maps (and GIS) effectively requires an understanding of how coordinate systems
Washington - B - 516
BIOSTAT516 Statistical Methods in Genetic Epidemiology Handout2, prepared by Kathleen Kerr and Stephanie MonksAutumn 2005Allele Frequencies, Genotype Frequencies, and Hardy-Weinberg EquilibriumEstablishing the genetics of the ABO blood group system was
Eckerd - MS - 242
MARINE GEOLOGY MS 242COURSE SYLLABUS SPRING 2008 PROF. LAURA WETZEL PURPOSE To provide a sound introduction to concepts that is appropriate for marine geologists with a wide range of intended fields of specialization. By the end of the course, the studen
NYU - DOCS - 4819
Issue Ownership and Representation: A Theory of Legislative Responsiveness to Constituency OpinionPatrick J. Egan Wilf Family Department of Politics New York University patrick.egan@nyu.edu January 12, 2009Abstract Scholars of politics have long endeavo
University of Toronto - ECE - 1770
Aspectizing Middleware PlatformsCharles Zhang, Hans-Arno JacobsenDepartment of Electrical and Computer Engineering Department of Computer Science University of Toronto 10 King's College Circle Toronto, Ontario, Canadacfw_czhang,jacobsen@eecg.toronto.ed
UNI - CS - 240
Computer Systems HW #1 Due: Friday, Sept 8 (4 PM in ITT 305 mailbox or under my office door, ITT 313)Type of Instruction Memory Access (Load and Store) Assembly Language lw $4, Mem sw $4, Mem lw $4, 16($3) sw $4, Mem move $4, $2 li $4, 100 la $5, mem add
Midwestern State University - AS - 350
AS 350 Reproductive Biotechnology Transgenic Animals Animal Cloning Embryo Transfer IVF, ICSIMay 1, 2009A transgenic animal is one that carries a foreign gene that has been deliberately inserted into its genome. Transgenic animals Mice 95% of all transg
University of Alaska Fairbanks - ZOOL - 575
Introduction to Biosystematics - Zool 575Introduction to Biosystematics Lecture 8 - Modern TaxonomyOutline - Modernization of alpha taxonomy 1. Tools - digital imaging, databases 2. Dissemination - WWW 3. Tools - Molecular data, species demarcation, phy
Iowa State - MAY - 0829
Project Plan and DesignMay08-29 Software Testing System for GlobalVetLinkDaniel Stewart - EE Joshua Carson -CprE Jordan Hager - CprE Dr. Greg Smith Advisor First Semester Dr Govindarasu Manimaran Advisor Second Semester Client Bob Shuka - GlobalVetLink
Washington University in St. Louis - CIS - 788
Multipoint Communication over IP and ATMRaj Jain The Ohio State University Columbus, OH 43210 Jain@CIS.Ohio-State.Edu http:/www.cis.ohio-state.edu/~jain/cis788-97/ Email questions to question@netlab.ohio-state.eduThe Ohio State UniversityRaj Jain 11-1
Georgia Tech - CHEM - 1310
Exam3 TestFormAChem1310PrintName_ Fall2008 11/24/2008 Dr.Williams Signature_This test is closed note/book. One 8.5 x 11 handwritten crib sheet (one sided) is permitted. Use a #2 pencil. Calculators are permitted. Computers, PDAs, and other electronic
UNC Wilmington - CSC - 221
A nI n t r o d u c t i o nt oO O Pw i t hJ a v aChapter 6 Selection StatementsOBJECTIVES After you have read and studied this chapter, you should be able to Implement selection control in a program using if statements. Implement selection control i
Oregon State University - PH - 585
UCSB - BREN - 211
Lespedeza leptostachya Status in Illinois - Plant Census DataSite Shoe Factory Road Prairie Hinsdale Prairie Waterfall Glen (introduction) HUM Railroad Prairie East HUM Railroad Prairie West Beloit Gravel Prairie Burr Oak Road Prairie Harlem Hills Winqui
Illinois State - COE - 091
C&I Department 533 #493 section 091 Restructuring Environment for the Improvement of Learning Spring 2009 Course Syllabus and Calendar Illinois State UniversityFacilitator: Dr. Michelle Mueller Office: 2000 Thomas Metcalf School Normal, IL 61790-7000 E-m
Oakland University - CSE - 233
1 Structure and Interpretation of Computer Programs Second Edition Assignment 8 Object-oriented programmingReading: Section 4.1Languages for Object-Oriented ProgrammingThis problem set is probably the most difficult one of the semester, but paradoxical
Lewis-Clark - M - 235
Introduction to Partial Dierential Equations - Day 2 2 Our main example: the Wave EquationIn this introduction to PDEs we will focus on the one dimensional wave equation. This equation models the vibration of an elastic string. We will assume that the tw
Rose-Hulman - ECE - 351
ECE351 Exam 1 Winter 2001-2PROBLEM 1: (40 Points)The circuit below is a power supply. VS is a 20 volt amplitude sine wave at 60 Hz, Vs = 20 sin(2 60t ) . Assume that the diodes are ideal.D1 Vo1+C1Vin+ -AMPLITUDE = 20 FREQUENCY = 60 D2a) What are t
Iowa State - NR - 30626
Retail Trade Analysis Woodbine "Then and Now"-1999-2004Presented by: Steve Adams, CEcD Iowa State University Extension Community and Economic DevelopmentIowa County Taxable Retail Sales, FY2004LYON OSCEOLA DICKINSON EMMET KOSSUTH WINNEBAGO WORTH MITCHE
Penn State - MMT - 143
scimetsyS, Inc. Robovisor DesignJustin Huntington, Michael Brehm, Katie Walder, Kevin Hauck, Rhys Ulerich, Jeffrey Monto, Michael SeltzerOverviewDesign ApproachThe Robovisor system was designed using modular decomposition, creating individual modules
Kansas State University - CHE - 650
Green Engineering: Green Engineering: Principles and Practice Principles and PracticeJennifer L. Anthony Department of Chemical Engineering Kansas State UniversityAdapted from presentations by E. Beckman (U. Pitt) and J. Brennecke (U. Notre Dame)Green
UMKC - BA - 544
Glossary of Forecasting Terms for BA 544 Supply Chain Management I have put this glossary together to highlight important concepts for our class. Only those concepts that have an * in front of them are important as far as testing. These, those with * shou
Central Washington University - G - 502
GEOL 502 Field Trip-Scablands and Continental Glaciation See GEOL 502 course website for course syllabus, expectations, field trip schedules, camping equipment, etc. (www.geology.cwu.edu GEOCLASSES Graduate Course catalog) Field Guide: Copies provided at
Azusa Pacific - CS - 470
Software Engineering in CS at APUCS 470 Software Engineering ISheldon X. Liang Ph. D.June 5, 2009 Azusa, CAAzusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http:/www.apu.edu/clas/computerscience/ June 5, 2
Campbell - DH - 148
ECON-201: MICROECONOMICS - SYLLABUS CAMPBELL UNIVERSITY- DISTANCE EDUCATIONPrerequisites: None. Instructor: Dr. H. Gholami Term: Spring Term I, 2009 January 5- February 28, 2009Please read this syllabus very carefully and pay attention to the weekly ass
Penn State - SCB - 223
Serge BallifMATH 535 Homework 7October 19, 20071. This exercise shows (part of) the fact every ring R can be considered as a subring of a ring with identity element. We mimic putting the subring i into the full ring of Gaussian integers: On S := , defi
Michigan State University - MATH - 320
Math 320-1 The Field AxiomsSpring 2006A eld is a set F with binary operations + (plus) and (times) that obey the following axioms: 1. Basic algebraic laws Law of closure: If a, b F then a + b and a b are both in F . Commutative Law: If a, b F then a + b
N. Illinois - MATH - 420
Little Results from the Axioms for IntegersLemma: The additive identity is unique. To see this, try adding two putative additive identities together. What do you get? Lemma: For any a Z, the additive inverse of a is unique. To see this, add a to two puta
Bowling Green - FI - 8000
Problems 1 through 8: You should use the Portfolio Frontier Spreadsheet posted on the website to solve these problems. For each problem, set the initial parameters in the relevant spreadsheet according to the table below. You should try to answer a few of
Washington University in St. Louis - CSE - 131
Oakland University - CSE - 598
Differentiated Services Problem with IntServ: scalability Idea: segregate packets into a small number of classes e.g., premium vs best-effort Packets marked according to class at edge of network Core routers implement some per-hop-behavior (PHB) Example
UMBC - MH - 100
Academic OneFile Printhttp:/find.galegroup.com/itx/printdoc.do?contentSet=IAC-Documents&d.Can the Cellphone Help End Global Poverty?(Magazine)(Jan Chipchase).Sara Corbett. The New York Times Magazine (April 13, 2008): p34(L). (6296 words)Full Text:COPY
Washington University in St. Louis - CSE - 131
Mich Tech - CH - 2212
CH 2212 Evaluation TestQuestions from: Quiz 4; CH 103; May 5, 1998 CH 103 Final Exam, May, 1998 One of the most important skills that a chemist (or scientist) must develop is the ability to detect when an answer just doesnt look right. Often you will be
Washington University in St. Louis - CSE - 573
XCP: Congestion Control for High Bandwidth-Delay Product NetworkBy Dina Katabi, Mark Handley and Charlie RohrsPresented by Shu and Santashil Slides Adapted from: Raymond Pun @ USCOutline Introduction XCP: The protocol Performance vs TCP + RED/CSFQ/REM
Maine - PDFS - 104
10 0 1. 0 2. 0 3. 0 4. 0 5. 0 6. 0 7. 0 8. 0 9. 010. 011. 012.UNIVERSITY OF SOUTHERN MAINE STUDENT INPUT FOR TEACHING FACULTY EVALUATIONS - MODERN AND CLASSICAL LANGUAGES - FALL 2004 519 STUDENTS RESPONDED ENTIRE DEPT QUESTION MEDIAN MEAN STD. NO 1 2 DE
Arizona - MIS - 480
E-Journals KM ArticlesOctober 21, 2004 MIS 580 Michael Fry & Yih-Jong Fu Department of Management Information System The University of Arizona1A Model of Knowledge Management And The N-Form CorporationBy Gunnar Hedlund 19942Article outline Introdu
Mich Tech - CE - 5710
Free Will: Now You Have It, Now You Don't - New York Timeshttp:/www.nytimes.com/2007/01/02/science/02free.html?ei=5087%0.January 2, 2007Free Will: Now You Have It, Now You Don'tBy DENNIS OVERBYEI was a free man until they brought the dessert menu aro
University of Hawaii - Hilo - EE - 491
Introduction to Embedded Microcomputer SystemsLecture 4.12.5. Programming numbers in assembly language w is signed 8-bit -128 to +127 or unsigned 8-bit 0 to 255 n is signed 8-bit -128 to +127 u is unsigned 8-bit 0 to 255 W is signed 16-bit -32787 to +32
Penn State - MAT - 5106
1. e) v(r) = f) U(r) = g) E =1 .q 4Eo r 1 . q1 x q2 4Eo r1 .q 4Eo r2p = qd Ue = p E h) E = q r 4EoR33. a) good luck b) Fb = qv x B 4. e) v(t) = Emsin(t) E(t) = 1 .q 4Eo r2q = CV f) I = C dV / dt B = . oi 4r g) using Farroday's law I'm sure that some
Lake County - ECE - 445
Smart Inventory Management SystemGroup 37 Masaki Negishi & Anthony Fai ECE 445 Senior Design April 27, 2005 SIMS: IntroductionSIMS provides a cost effective solution for the management of inventory which leverages RFID technology. Combines an antenna
University of Toronto - CS - 343
Introduction to Database Management Systems 343 Problem Set 4Both hard copy and electronic submission (using name A4.pdf or A4.txt) must be submitted. 1. Normal Forms 15pt For each relation schema and set of functional dependencies, state whether the sch
Acton School of Business - STAT - 670
An Introduction to Hidden Markov ModelsL. R. .Rabiner B. H. JuangThebasictheoryofMarkovchains has been known to mathematicians and engineers close to 80 years, but it is for only in the past decadethat it has been applied explicitly to problems in speec
Washington - BE - 571
Community design through action research LArch 571/598Akanksha Singh Assignment #3 06/01/2004Interviewing is one of the most essential tool for research work. It can be in a highly structured format like a survey interview (with fixed questions in a pre