Object Oriented Software Engineering Practical software development using UML and Java By Timothy C Lethbridge and robert Laganiere McGraw-Hill 2001 Intemational ISBN 0-07-709761-0 US ISBN0-07-283495-1 Public Answers to Selected Exercises- Version 1.9(August, 2002) o 2002 Timothy C Lethbridge and Robert Laganiere The following contains answers to a subset of the exercises in the book, along with explanations of some aspects of the answers. In some cases the provided answers are more detailed those that would be expected from students. Also note that some questions are subjective, so readers may have responses different from those written here The answers provided here are publicly available on the website so as to enable students to practise. Generally speaking, the answers given here are parts a of multi-part questions; in exercises with many parts, answers may also be given to parts c and e. The full set of answers is only available to instructors as a separate password-protected document le update these answers from time to time, adding improved explanations, altemative answers, and extra exercises. You can contact us at tcl@site. ottawa. ca with suggestions. Items which we plan to complete or augment at a later date are marked in green Pleaselookatourwebsite(www.llosengcom)forotherinformationaboutthisbookincluding a knowledge base containing many of the basic facts from the book Videos of Tim Lethbridge presenting lectures based on the book The slides that have been prepared for professors who teach using the book
O bj ect O ri e ntedSo ftw ar e E ng in e er in g : P ra cti ca l softw a red e ve lo p me nt usin gU MLan d Java By Timothy C. L e thbr idge a nd Robe rt La ga niè re McG ra w -H ill 2001 I nter national I SBN0- 07-709761- 0 U S ISBN 0- 07- 283495- 1 PublicA ns wer s t o Se lec te d Exe r cise s–Ve rs ion 1 .9(A ugust , 2 00 2) © 2002 T imothy C. Le thbridgea nd Rober t L aganièr e T he f ollow ing c ontains answe rs to a subse t of t hee xer cises in the book, a long w ith e xpla nations of some aspe c ts of the a nswe r s. I n somec ase s theprovided answ e rs a r e mor e de taile d those tha t would bee xpe cted fr om stude nts. Also notethat some que stions a resubjec tive, so r e ader s may ha vere sponses diff e re nt fr om those w ritte n her e. T hea nsw er s provided he re ar e public ly a vaila ble on the we bsite so a s to ena ble stude nts to pra c tise . G ene ra lly spe a king, the a nsw er s give n he r e ar e par ts a of multi-pa rt questions; in exe rc ise s with ma ny pa r ts, a nswe r s ma y a lso be given to par ts c and e . T hef ull se t ofansw e rs is only a va ila bleto instr uctor s a s asepa ra tepa ssw or d- prote c te d doc ume nt. W e update the se answ e rs f r om time to time , adding improved e xplana tions, alter na tive a nswe r s, a nd extrae xer cises. Y ou c an c ontac t us a t tcl@site .uottaw a .c a with sugge stions. I tems w hich we plan to c omple te or a ugment a t a late r da te ar e mar ke d in gre en. Ple aselook a t ourw e b site (w ww .lloseng.c om)f orothe rinf ormation a bout this book, inc luding: • Aknow le dgeba sec ontaining many of thebasic fa c ts f r om the book • V ide os ofT im Le thbridgepre senting le c ture s base d on the book. • T heslide s tha t ha ve be e n pr e pa re d f orpr of e ssor s w ho te ac h using thebook
PUBLIC ANSWERS TO EXERCISES Chapter 1. Software and Software Engineering El.1 p 5 Classifying software a)*Custom; real-time c)Generic; real-time(but soft real-time El.2 p. 10 Stakeholder reactions to situations particular type of work. On the other hand, he or she may be relieved about not being put out of wort i a)*. The user may be disappointed, since he or she might be looking forward to no longer having to do ince many people believe that software systems are easy to develop; they underestimate the complexity of tasks that are to be automated. The customer might consult some other software engineer to obtain a second opinion The developers will probably move on to other work The development managers may be disappointed at not having the opportunity to do further work on the project E1.3 p 12 Prioritizing quality attributes a)*Reliability will be paramount for the spacecraft software. It would be sad if the spacecraft did not make it into orbit after all that time, although no lives would be lost. Efficiency might be important since processors from 20 years earlier are far slower than today's devices. Usability will likely not be an issue since the software will run autonomously and report any feedback to experts; furthermore the software cannot be interactive since it takes considerable time to send signals to and from Pluto at the speed of light Maintainability is also likely to be a minimal concern since this software is likely to only be used once However, there remains the possibility that the software could be used on other systems, or will need to be changed as last-minute bugs are fixed c)* Maintainability will likely be the most important concern since data processing software tends to evolve Reliability will also be of considerable importance: Bill printing must be accurate, since it can be costly to ify mistakes. Usability of the bills themselves will be important because ordinary people have to derstand them Efficiency should not be a concern THESE ANSWERS SUPPORT THE BOOK OBJECT ORIENTED SOFTWARE ENGINEERING
PUBLI C A NSW ERS T O EX E RCISE S PA2 T HE SEAN SW E RS SU PPORTT HEBO OK O BJ ECT O RI E NTEDSO FTW AR E E NG INE ER ING : Chapt er 1. Soft w ar e and Soft war e Engineer ing E 1.1 p. 5 Classify ing software . a )*Custom; re a l- time. c )*G ener ic; r e al-time( but soft re al- time ) . E 1.2 p. 10 Stak e holde r re actions to situations. a )*• T he use r ma y be disappointed, sinc e he orshe might belooking f or wa r d to no longer ha ving to do this par tic ulartypeofw ork. O n theothe r ha nd, heor shema y bere lie ve d a bout not being put out ofw or k. • T he c ustom er ma y be disappointed at not be ing a ble to save mone y; he or she ma y also be surpr ised, since ma ny pe ople be lie ve that softw ar e syste ms ar e e asy to develop; they unde re stima te the c omple xity of ta sks tha t a reto be a utoma te d. The c ustomermight c onsultsome other softwa r e enginee r to obtain asec ond opinion. • T he develope rs will pr oba bly move on to othe rw or k. • T he de ve lopme nt m anage rs ma y be disappointed at not ha ving the opportunity to do f ur the r w or k on thepr ojec t. E 1.3 p. 12 Prioritizing qualityattribute s a )*R eliabilit y will bepa ra mount f or thespa c ec ra f t sof tw ar e . It would be sad ifthe spac e cr af t did not make it into orbit af te r a ll that time , a lthough no live s w ould be lost. Eff ic iency might be impor tant since proce ssors fr om 20 ye ar s e ar lie r ar e f ar slow e r tha n today’s de vic es. U sabilit y will like ly not be a n issue since the sof tw a re w ill r un autonomously and r epor t a ny fe edbac k to exper ts; f ur the rmore the sof tw ar e c annot be inter a ctivesinc e it ta ke s c onsider a ble time to se nd signa ls to a nd fr om Pluto a t thespee d of light. M aint ainability is a lso like ly to be a minima l c onc er n since this softw ar e is likely to only be used once . H ow eve r, ther e r emains thepossibility that the sof tw ar ec ould beused on othe r syste ms, orw ill nee d to be c ha nge d as la st- minute bugs ar ef ixe d. c )*M aint ainability will like ly be the most impor tant c once r n since da tapr oc essing sof tw a rete nds to evolve. R eliabilit y will also beofc onsider a ble impor tance : Bill printing must be a c cura te, sinc e it ca n be c ostly to r ec tif y mista ke s. U sabilit y of the bills themse lve s w ill be impor ta nt be c ause or dinar y people have to under sta nd them. Eff ic iency should not be ac onc er n
PA3 PUBLIC ANSWERS TO EXERCISES Chapter 2. Review of object orientation E2.1 p 32 Distinguishing among classes and instances The class names in the following answers could vary slightly. The points in parentheses are of lesser importance, and are for those who have read Chapter 5 a)*Instance of Automobilecompany(or perhaps just Company c)*Class, subclass of Person. (In Chapters 5 and 6, we will see that it might be better to make this a subclass of PersonRole) e)"Instance of Person E2. 2 P 33 Detecting bad class names and improving them a)*Bad. Is this a particular vehicle (which might better be called something like Locomotive, or RollingstockConfiguration)or a scheduled run(RegularlyScheduledRun)that could use any vehicle, or the run on a particular day( specificRun ) We will discuss this kind of problem in more detail in Chapter 6 in the context of the Abstraction Occurrence pattern c)*Bad. The word" is inappropriate in a class name. Call it simply sleepingCar e)*Bad. It should not be plural: Route would be bette E2.3 P 33 Naming different classes derived from words with multiple English meanings. vofritle a)*Title: Describes published books independently of the number of copies Copyofritle: or perhaps LibraryItem: Represents physical books(as well as other things, such as videos )that the library places on its shelves c)*RegularlyScheduledFlight: has a flight number, departure time, origin and destination and is flown every day; SpecificFlight: flies on a particular day E2. 4 pp 34-35 identifying attributes In this question and the next, there are many alternatives, a few possibilities are shown here. In particular ometimes certain attributes could be represented as associations instead -these are shown in parentheses a)*name, description, (producer, distributer) c)*date, startTime, endTime, description, soundAlarmWhenstarting,(room) e)'callerNumber, calledPartyNumber, isConnected, startTime, currentcell signalStrength, totalCost E2.5 p 35 Identifying associations a)boughtFrom ProductionCompany, produced By: Producer, episodes Episode leadActors Actor c)*meetingRoom: MeetingRoom e)*caller: CallParty, called: CallParty E2.6 P. 35 Differentiating between variables and objects E2.7 p. 36 ldentifying operations In the following, operations that would probably be polymorphic are shown in italics, however, exactly which operations are polymorphic would depend on the design. a)*getArea, getPerimeterLength, getPoints, move, resize, rotate flipHorizontally, flipVertically E2.8 p. 40 Identifying poor generalizations a)*Bad: You can't say 'A Canadian dollars is a money'; also CanadianDollars should be an instance of Currency c)*Probably OK e)"Bad: Account12876 would be instance of BankAccount(or some subclass of BankAccount) E2.9 No public C 2002 TIMOTHY C. LETHBRIDGE AND ROBERT LAGANIERE
PA3 PUBLI C A NSW ERS T O EX E RCISE S © 2002 T IMO TH Y C. LE T HBRI D GEA N D RO BERT L AG AN I ÈRE Chapt er 2. Revi ew of object or i entat ion E 2.1 p. 32 Distinguishing am ong c lasse s and instanc es T he c lass names in the following answe rs could var y slightly. T he points in pa r enthe se s a re of lesser impor tance , a nd ar e f orthose w ho ha ver e ad Chapte r5. a )*I nsta nceof AutomobileCompany. ( orpe rha ps just Company) c )*Cla ss, subc la ss of Person. ( In Chapter s 5 a nd 6, w ew ill seethat it might be be tte r to ma ke this a subcla ss of PersonRole) e )*I nsta nceof Person. E 2.2 p. 33 De te c ting bad c lass name s and im proving them a )*Bad. I s this a par tic ular ve hic le ( w hich might better be c alled some thing like Locomotive, or RollingStockConfiguration) or a sche dule d r un (RegularlyScheduledRun) tha t c ould use a ny ve hicle , orthe r un on apa rtic ula r day ( SpecificRun) ? Wewill disc uss this kind ofproble m in mor e detail in Cha pte r 6 in thec ontext of theA bstra ction O c curr e nc e patte r n. c )*Bad. T hew ord ‘ D ata’is inappr opr ia te in a cla ss na me . Call it simply SleepingCar. e )*Bad. I t should not beplur al: Route would be bette r . E 2.3 p. 33 Naming diffe re nt classes de riv ed fromwords with m ultiple E nglish m eanings. a )*Title: D esc ribe s publishe d books independently of the number of c opies CopyOfTitle: or per ha ps LibraryItem: Repr esents physica l books (a s w ell a s other things, such a s vide os) tha t thelibr ar y pla c es on its she lve s. c )*RegularlyScheduledFlight: has a flight numbe r , de par tur e time, or igin and destination a nd is f lown ever y day; SpecificFlight: f lie s on a pa r ticularda y. E 2.4 pp. 34-35 I de ntify ing attribute s I n this que stion a nd the next, ther e a re ma ny alte r na tives, a f ew possibilitie s a re show n her e. In pa rtic ula r sometime s c er ta in attributes c ould be re pre se nte d a s assoc ia tions inste ad – thesea reshow n in par enthe se s. a )*name, description, ( producer, distributer) c )*date, startTime, endTime, description, soundAlarmWhenStarting, ( room) e )*callerNumber, calledPartyNumber, isConnected, startTime, currentCell, signalStrength, totalCost E 2.5 p. 35 Identifying assoc iations a )*boughtFrom:ProductionCompany, producedBy:Producer, episodes:Episode, leadActors:Actor c )* meetingRoom: MeetingRoom e )*caller:CallParty, called:CallParty E 2.6 p. 35 Diffe re ntiating betwee n v ariable s and obje cts a )*O bjec t E 2.7 p. 36 Identifying ope rations I n thef ollow ing, ope ra tions tha t w ould pr oba bly be polymor phic a reshow n in ita lics, how e ve r, exac tly w hic h ope ra tions ar e polymorphicw ould de pend on the design. a )*getArea, getPerimeterLength, getPoints, move, resize, rotate, flipHorizontally, flipVertically E 2.8 p. 40 Identifying poor ge neralizations a )*Bad: Y ou c a n’ t say ‘ A Cana dian dolla rs is a mone y’ ; a lso CanadianDollars should be an instanc e of Currency c )*Proba bly O K . e )*Bad: Account12876 would be insta nceof BankAccount (or some subcla ss of BankAccount) E 2.9 No public answe r
PUBLIC ANSWERS TO EXERCISES E2. 10 pp. 41-42 Arranging potential classes into inheritance hierarchies (See also E5.21, p. 189) In the following, the hierarchies are shown using indented text to save space. Whether it would be appropriate to actually include all the classes in a given system would depend on the applications requirements. There are many possible variations on these answers. Note: See also E5.21 for additional exercises based on these a)*In this problem we create two separate hierarchies, Vehicle and Partofvehicle. These could also ave something like Machine as a common superclass, although the problem suggested creating separate Vehicle Landvehic⊥e( Added) Car SportscAr B AirVehicle(Added) Aeroplane Amphibious vehicle artofvehicle Engine JetEngine ElectricMotor Cansmlss1。n Vehicle could instead be divided into PoweredVehicle and Unpoweredvehicle; multiple inheritance could be then used for superclasses of the vehicle leaf classes c)*Schedule(We will learn later that this may not be needed since the whole system stores the schedule) RegularlyScheduledTrip(Added as a superclass representing something that runs at a given time) RegularlyScheduledExpressBus(renamed for clarity) ActualTrip( Runs at a given time on a given day; could also be called Run) CharteredTrip(Renamed for clarity) (Added to properly compl 1P UnscheduledTrip(Runs on a route, but not at the normal time) BusVehicle(Renamed from busto distinguish different types of bus) LuxuryBus e)*Currency( Canadian Dollars and US Dollars are Instances) ExchangeRate(Attributes or associations could be fromCurrency, tocurrency, rate FinancialInstitution(Added) Credi tunion Creditcardcompany(Visa and Master Card are instances) FinancialInstrument ReusableFinancialInstrument(Added) Creditcard Debitcard SingleTransactionInstrument (Added) BankAccount ElectronicDevice (Added) AutomaticTellerMachine(better than BankMachine) BankBranch THESE ANSWERS SUPPORT THE BOOK OBJECT ORIENTED SOFTWARE ENGINEERING
PUBLI C A NSW ERS T O EX E RCISE S PA4 T HE SEAN SW E RS SU PPORTT HEBO OK O BJ ECT O RI E NTEDSO FTW AR E E NG INE ER ING : E 2.10 pp. 41-42 A rranging potential c lasse s into inheritanc e hie rarchie s ( Se ealso E 5.21, p. 189) I n thef ollow ing, thehie r ar chies a r e shown using indented te xt to savespa c e. W hethe rit w ould bea ppr opr ia te to ac tua lly inc lude a ll the cla sses in agive n system w ould depend on thea pplic a tion’ s re quire ments. T he r e ar e many possible va riations on the se a nsw er s. Note: Se e also E5.21 f or additional e xer cises ba se d on the se proble ms. a )*I n this pr oblem we c r ea te tw o separ a te hier ar c hies, Vehicle and PartOfVehicle. T he se could a lso have something like Machine as a common super cla ss, a lthough the pr oblem sugge sted cr ea ting separ a te hie ra r chie s. Vehicle LandVehicle (A dde d) Car SportsCar Truck Bicycle AirVehicle (A dde d) Aeroplane AmphibiousVehicle PartOfVehicle Engine JetEngine ElectricMotor Wheel Transmission Vehicle could instea d be divided into PoweredVehicle and UnpoweredVehicle; multiple inher ita nc ec ould bethen used for super c la sse s ofthe vehic le le a f cla sses. c )*Schedule (W e w ill lea rn la te rtha t this may not be ne e de d sincethe w holesyste m store s thesc he dule) RegularlyScheduledTrip (A dde d as a super cla ss r e pr ese nting some thing tha t r uns a t agive n time) RegularlyScheduledExpressBus (r ena me d f orc lar ity) BusRoute ActualTrip (Runs a t agive n time on a given da y; c ould a lso be ca lle d ‘ Run’ ) CharteredTrip (Rena me d f orc lar ity) ScheduledTrip (A dde d to pr ope rly c omple me nt unscheduledTrip) UnscheduledTrip (Runs on ar oute, but not a t thenormal time ) BusVehicle (Rena me d f rom ‘ bus’to distinguish diff e re nt type s of bus) LuxuryBus TourBus e )*Currency (Cana dian Dolla rs a nd US Dolla rs a r e Insta nc e s) ExchangeRate (A ttr ibute s orassoc ia tions c ould be fromCurrency, toCurrency, r ate ) FinancialInstitution ( Adde d) Bank CreditUnion CreditCardCompany (V isaa nd Ma ste rCar d a reinsta nc es) FinancialInstrument ReusableFinancialInstrument ( Adde d) CreditCard DebitCard SingleTransactionInstrument ( Adde d) Cheque BankAccount Loan ElectronicDevice ( Adde d) AutomaticTellerMachine (betterthan BankMachine) BankBranch
PAS PUBLIC ANSWERS TO EXERCISES E2. 11 p. 47 Describing how polymorphic implementations of certain shape operations would work. a)*translate: In SimplePolygon (as inherited by Rectangle and Regularpolygon), and EllipticalShape(as inherited by circle), the method translate would move the center c)getArea: In Rectangle, the method getArea would return height width In RegularPolygon, it would compute the area by dividing the polygon into numPoints individual iangles(see the answer to E2. 30 for the detailed algorithm). Once this area is calculated, the total area of the RegularPolygon would be calculated by multiplying the area of each triangle by numPoints In Circle, the method getArea would return pi*radius E2. 12 No public answer E2. 13 P. 47 Incorporating new classes into an existing class hierarchy that contains considerable polymorphism a)*IsoscelesTriangle: One might think of making this a subclass of ArbitraryPolygon, however that would be inappropriate since you dont want it to inherit methods such as addPoint and removePoint. a better solution is to make it a subclass of SimplePolygon. As attributes you would have to store the baseLength and height, or else you could store one of the two values for angles and the length of one of the sides, letting the other angle value and side be computed when needed. As methods, you would need changeScale, setBaseLength, setHeight, getArea getPerimeterLength, getvertices, getBoundingRect, getBaseAngle, getTopAngle and perhaps setBaseAngle and setTopAngle E2. 14 No public answer E2. 15 No public answer E2. 16 No public answer E2.17 P. 49 Determining when dynamic binding is needed in a set of polymorphic methods This exercise has turned out to be particularly useful to ensure students really understand the implications of polymorphism. Before assigning this exercise, it has proved to be necessary to explain the material on pages 48 and 49 particularly carefully, with several examples. Note that the exercise has the assumption, that the compiler knows that no new classes or methods can be added to the hierarchy", it is worth reminding students that this is not generally true in Java(you can add a subclass unless the class is declared final, and you cannot declare a non-leaf class to be final) a) *Invoking getPerimeterLength on a Rectangle variable: No dynamic binding is needed since ectangle is a leaf class and so the variable could only ever contain an instance of that class. The local method in Rectangle would always be called c)*Invoking getBoundingRect on a Polygon variable: Dynamic binding would be needed, since either the method in Polygon or the one in Rectangle might have to be executed depending on which class of object is placed in the variable at run time E2.18 P. 51 Researching products that claim to be object-oriented to determine if they really are. The answer to this question will vary over time, depending on what products are availabl E2. 19 p. 53 Using documentation to look up library classes and thus better understand a prog This is a purely practical exercise. Its purpose is to encourage students to get in the habit of using documentation E2.20 No public answer E2.21 No public answer E2. 22 No public answer E2.23 No public answer E2. 24 No publi c answe C 2002 TIMOTHY C. LETHBRIDGE AND ROBERT LAGANIERE
PA5 PUBLI C A NSW ERS T O EX E RCISE S © 2002 T IMO TH Y C. LE T HBRI D GEA N D RO BERT L AG AN I ÈRE E 2.11 p. 47 De sc ribing how poly m orphic im ple me ntations of c ertain shapeoperations would work. a )*translate: I n SimplePolygon (a s inher ite d by Rectangle and RegularPolygon) , and EllipticalShape (a s inher ite d by Circle) , themethod translate would movethe center. c )*getArea: I n Rectangle, the me thod getArea would r eturn height * width. I n RegularPolygon, it w ould compute the ar e a by dividing the polygon into numPoints individua l triangle s ( se e thea nsw er to E 2.30 f orthe de taile d a lgorithm). O ncethis a r eais c alc ulate d, the total a r eaof the RegularPolygon would be c alculated by multiplying the a re a of ea c h tr iangle by numPoints. I n Circle, theme thod getArea would r eturn pi * radius2 . E 2.12 No public answe r E 2.13 p. 47 Incorporating new c lasse s into an e xisting c lass hie rarchy that c ontains c onside rablepoly morphism. a )*IsoscelesTriangle: O ne might think of ma king this a subcla ss of ArbitraryPolygon, how e ve r tha t w ould be inappr opr ia te since you don’t w a nt it to inher it me thods such as addPoint and removePoint. A be tter solution is to ma ke it a subc lass of SimplePolygon. A s a ttributes you w ould have to storethe baseLength and height, or e lse you c ould store one of thetwo va lue s fora ngles a nd the le ngth of one of the sides, letting the othe r a ngle va lue a nd side be c omputed w hen ne eded. A s methods, you would ne ed changeScale, setBaseLength, setHeight, getArea, getPerimeterLength, getVertices, getBoundingRect, getBaseAngle, getTopAngle, a nd pe rhaps setBaseAngle and setTopAngle. E 2.14 No public answe r E 2.15 No public answe r E 2.16 No public answe r E 2.17 p. 49 De te rmining whe n dy nam icbinding is nee ded in a se t of poly m orphic me thods. T his e xe rc ise ha s tur ne d out to be par tic ular ly use ful to ensur e stude nts r e ally unde r stand the implic ations of polymorphism. Be fore assigning this exer c ise, it ha s pr ove d to be ne ce ssa ry to e xplain the ma te r ia l on pa ges 48 and 49 par tic ular ly ca r ef ully, w ith se ve ra l e xa mples. N ote tha t the exer c ise has the assumption, “ that the c ompilerknow s tha t no ne wc la sse s or me thods ca n be added to thehier a rc hy” ; it is w orth r eminding stude nts tha t this is not gene ra lly true in Java ( you c an a dd a subcla ss unle ss the c la ss is de clar e d final, a nd you c annot dec lar e anon- le afclass to be final) . a )*I nvoking getPerimeterLength on a Rectangle va ria ble: No dyna mic binding is ne e de d since Rectangle is a le af class a nd so the va r ia ble c ould only eve r conta in an instanc e of that class. Theloc a l method in Rectangle would a lw a ys bec alled. c )*I nvoking getBoundingRect on a Polygon va ria ble: Dyna mic binding w ould be ne ede d, sinc e e ithe r the me thod in Polygon or the one in Rectangle might have to be exe cute d depe nding on w hich class of objec t is pla ce d in thevar iableat r un time. E 2.18 p. 51 Re se arc hing products that c laim to beobje ct- orie nte d to de termine if theyre ally are . T hea nsw erto this question will va r y ove r time, de pe nding on w ha t produc ts ar e a va ila ble. E 2.19 p. 53 Using doc ume ntation to lookup library c lasse s and thus better unde rstand a program. T his is a pur ely pra c tica l e xe r cise . I ts purpose is to e nc our age stude nts to get in the ha bit of using doc ume ntation. E 2.20 No public answe r E 2.21 No public answe r E 2.22 No public answe r E 2.23 No public answe r E 2.24 No public answe r
PUBLIC ANSWERS TO EXERCISES PA6 E2. 25 No public answer E2.26 No public answer E2. 27 No public answer E2.28 No public answer E2. 29 No public answer E2.30 No public answer E2.31 No public THESE ANSWERS SUPPORT THE BOOK OBJECT ORIENTED SOFTWARE ENGINEERING
PUBLI C A NSW ERS T O EX E RCISE S PA6 T HE SEAN SW E RS SU PPORTT HEBO OK O BJ ECT O RI E NTEDSO FTW AR E E NG INE ER ING : E 2.25 No public answe r E 2.26 No public answe r E 2.27 No public answe r E 2.28 No public answe r E 2.29 No public answe r. E 2.30 No public answe r E 2.31 No public answe r
PA7 PUBLIC ANSWERS TO EXERCISES Chapter 3. Basing software development on reusable technology E3. 1 p. 63 Researching resources on the Internet that discuss aspects of reuse The answer to this question will vary since web pages are continually being added, deleted and changed E3. 2 p 63 Analysing information about reuse. For discussion only 3.3 pp. 69-70 Determining the services that should be present in a framework a)"Reservation framework Add an instance of whatever that can be reserved(e. g. a book, a place on a flight, a seat in a theatre) Add an instance of whatever the reservation is made on behalf of(e.g. a library patron, a passenger,a theatre-goer) Make a reservation · Delete a reservation E3.4 P. 70 Determining differentiating features of framework-based applications, as well as its hooks and slots a)*Reservation framework Differentiating features The classes of objects that can be reserved and their attributes, associations and other operations The attributes of the reservation itself, and perhaps subclasses representing different types of reservation The classes of objects that a reservation can be made on behalf of The user interface Rules regarding the reservation such as who can make one whether the item can be reserved eto · Hooks A function that would be called when a reservation is complete(e.g. to send an email) An function to call when reservations are full that could be used, for example, to add a waiting list, or to give some form of notification to the user A function called to load a reservation from a database a function called to save a reservation There may be no slots in this system E3.5 p. 70 Determining the range of applications that might benefit from a framework. a)*Reservation framework A library system, where you can reserve items that are already checked out Reservation of seats on any kind of transportation system Reservation of entertainment tickets E3.6 p. 70 Evaluating alternative approaches to designing a framework. a) *If you started with a vertical framework for a frequent flier program, you would have a lot of facilities already developed, some of which would be quite specific to the frequent flier domain. The following gives some ideas of the services, slots and hooks that might be provided; many variations on this answer are possible 1. Services Maintenance of frequent flier accounts to which points(miles) can be added and redeemed (i.e adding new accounts; deleting accounts) Keeping of basic personal information(name, address, points)about each frequent flier, with methods to update this information(which would call the first hook below to allow managing of additional information) Keeping of a log of flights to be used when producing reports(would also be capable of recording other transactions, e.g. points awarded for renting a car) Methods to add, delete and query the number of points in the account C 2002 TIMOTHY C. LETHBRIDGE AND ROBERT LAGANIERE
PA7 PUBLI C A NSW ERS T O EX E RCISE S © 2002 T IMO TH Y C. LE T HBRI D GEA N D RO BERT L AG AN I ÈRE Chapt er 3. Basi ng sof tw ar e developm enton r eusable technol ogy E 3.1 p. 63 Re se arc hing re sourc e s on the I nternet that disc uss aspe cts of re use . T hea nsw erto this question will va r y sincew e b pa ges a r e continua lly being adde d, de leted and c ha nge d. E 3.2 p. 63 Analy sing information about re use. Fordisc ussion only. E 3.3 pp. 69-70 D eterm ining these rv ice s that should be pre se nt in a frame work. a )*R eser vat ion f ram ew or k. • A dd a n instanc e ofwhate ve r tha t c an ber ese rved (e .g. abook, apla c e on a flight, a se a t in a the atre ) • A dd a n instance of w hateve r the r ese rvation is made on behalf of ( e.g. a libra ry pa tr on, a pa sse nger , a the atr e- goe r) . • Make ar ese rvation • D eleteare se r va tion E 3.4 p. 70 De te rmining diffe re ntiating fe ature s of fram ework -base d applications, as well as its hook s and slots. a )*R eser vat ion f ram ew or k. • D if fe r entia ting fe ature s: - T hec lasse s of objec ts tha t ca n be r eser ved a nd the ira ttr ibute s, assoc ia tions a nd otheroper ations - T he a ttr ibute s of the r ese rvation itse lf , a nd pe rha ps subc la sse s r epre senting dif fe re nt types of r eser vation - T hec lasse s of objec ts tha t a r eser vation c an bema deon beha lfof - T heuserinte rf a ce - Rules re ga r ding the r eser vation, suc h as who c an ma keone, w hethe rtheitem ca n be re ser ve d, etc . • H ooks: - Af unc tion that would be c alle d w he n ar e se rva tion is c omple te (e .g. to send a n e ma il) - A n function to c all w he n r eser vations ar e‘ full’that c ould be use d, f or exa mple , to a dd awa iting list, or to givesomeform ofnotific ation to theuser . - Af unc tion ca lle d to load a re ser va tion f rom adata ba se . - Af unc tion ca lle d to sa veare se r va tion. • Slots: - T he rema y be no slots in this syste m. E 3.5 p. 70 De te rmining therange of applications that m ight benefit from a frame work. a )*R eser vat ion f ram ew or k. • Alibr ar y syste m, whe reyou ca n r ese rve ite ms that ar e a lr ea dy che cked out • Reser vation of sea ts on a ny kind oftr ansporta tion syste m • Reser vation of e nter tainme nt tickets E 3.6 p. 70 Ev aluating alte rnativeapproac he s to de signing a frame work. a )*I f you sta r te d w ith a ver tic al fr ame work for a f re que nt flie r progra m, you w ould ha ve a lot of f ac ilities a lr ea dy de velope d, some of w hic h would be quite spe cific to the f r eque nt flier doma in. T he following gives some idea s of the se rvic e s, slots a nd hooks tha t might be pr ovide d; ma ny va riations on this answe r a repossible. i. Ser vic es: • Mainte na nc e of f re que nt f lie r a cc ounts to w hic h points (mile s) c a n be adde d a nd re de e me d ( i.e. a dding new ac counts; de le ting a cc ounts) • K ee ping of ba sic per sonal infor ma tion (na me , a ddre ss, points) a bout ea c h fr e quent f lie r, w ith methods to upda te this inf or ma tion ( whic h w ould ca ll the f ir st hook be low to a llow ma naging of a dditional infor ma tion) • K ee ping of a log of f lights to be used w hen pr oduc ing r e ports ( would a lso be c apa ble of re c or ding othertr ansac tions, e .g. points a wa r de d f orr e nting ac a r) . • Methods to add, de le te and que r y thenumberofpoints in theac count
PUBLIC ANSWERS TO EXERCISES Generic mechanism, given two cities, that would calculate how many points would be required to fly between them for free for a given user. This would be called when customers are doing queries and also when a person actually books a free flight to determine how many points to deduct This would call the first slot below to do detailed calculations Generic mechanism, given two cities, that would calculate how many points to credit to a particular frequent flier who pays for a ticket. It would be called when the user is making queries, and also when a person actually takes a flight, in order to credit points. This would call the second slot below for detailed calculations Generic mechanism that runs every month, calling the slot(below) for producing reports, and the hooks(below) for deleting inactive accounts, and perhaps promoting users to different classes i1. Slots(code that must be provided) a method to evaluate rules regarding how many points are required to fly certain routes for free A method to evaluate rules regarding how many points are obtained from flying certain routes (might be specific to certain classes of frequent flier, certain times, etc. A method to produce a formatted printout of a frequent fliers account(each airline may want to make these appear stylistically different from other airlines). Note that instead of creating a slot, this functionality could be left out of the framework entirely Note that the user interface would have to be provided but would probably not actually appear as slots in the basic system; the user interface would be a separate subsystem that would simply call the iii. Hooks(places where optional add-ons can easily be plugged in) Ability to manage additional types of information about frequent fliers(e. g. work address, email, ) beyond the basic minimum information. Different airlines might want to keep different kinds of information for use in marketing etc ability to have different classes of users (e.g. prestige users who have accumulated large numbers of Mechanism to delete accounts after a certain time period with no activity(this might be activated by the monthly run that prnts reports) ability to add different kinds of points to be used for different purposes(e.g. some airlines, in addition to miles, also keep track of a separate count of miles flown in first class; such points might have different rules, such as expiring after the end of a year) E3.7 P. 70 Eraluating whether or not one should first develop a framework when designing an application a)* Arguments in favourof developing a full frequent flier framework Developing the framework improves your overall design. Since you would have to build flexibility into the framework to allow it to be used by others, you would benefit from that flexibility when you have to make changes yourself As a consequence of the above, you would expect maintenance costs to be reduced; you would also expect to be able to respond faster to market-driven requirements changes You might be able to sell your framework to others, or to provide frequent-flier services to other smaller airlines Should two airlines using the same framework decide to work together in an alliance(or to merge)their systems would be more compatible with each other, reducing costs E3.8 P 74 Evaluating whether an application should be designed as a client-server system or not a ) *Word processors are not normally designed using a client-server architecture. The following are some of the reasons why not People typically use word processors on laptop computers or other machines that may not be connected to any network Although people do share word-processed data, most people work on their own local copy and then share it when they are finished It might be beneficial to allow a word processor to optionally connect to a server to do such things as load and save data, or to enable two people to edit the same document concurrently. However it would still be necessary to ensure that the user could operate the program while not connected THESE ANSWERS SUPPORT THE BOOK OBJECT ORIENTED SOFTWARE ENGINEERING
PUBLI C A NSW ERS T O EX E RCISE S PA8 T HE SEAN SW E RS SU PPORTT HEBO OK O BJ ECT O RI E NTEDSO FTW AR E E NG INE ER ING : • G ener ic me c ha nism, give n two c ities, tha t w ould ca lcula te how many points w ould be re quire d to f ly be tw ee n the m f or fr ee for agive n use r. T his w ould be ca lle d w he n c ustomer s a re doing que rie s, a nd a lso w hen a pe rson ac tua lly books a f re e f light to deter mine how ma ny points to de duct. T his w ould ca ll the f ir st slot be lowto do de taile d c alc ulations. • G ener ic me c ha nism, give n two c ities, tha t w ould ca lcula te howmany points to c re dit to apa rtic ula r f re que nt f lie r w ho pa ys f or a tic ke t. It would be c alle d w he n the user is ma king quer ies, a nd a lso w he n aper son a c tually ta kes aflight, in orde r to cr edit points. This would c all these cond slot be low f orde ta ile d ca lcula tions. • G ener ic me c ha nism tha t runs eve ry month, c alling the slot ( be low ) f or pr oduc ing r e ports, and the hooks (below)f or de leting ina c tiveac counts, and per ha ps pr omoting use rs to dif f er ent c la sse s. ii. Slots (c odetha t must be provided) • Amethod to e va lua terule s r ega rding how ma ny points ar ere quire d to fly c er tain r oute s f orfr ee . • A method to e va lua te rule s r ega rding how ma ny points ar e obta ined fr om flying ce r ta in route s ( might be spe cif icto c er tain c la sse s offr equent f lier , c er tain times, e tc .) • A method to produc e a f or matte d pr intout of a fr e quent f lie r’ s a cc ount (e a ch a irline may wa nt to make the seappe a r stylistica lly dif f er ent f rom othe r air line s). N otethat instea d of c re ating a slot, this f unctionality c ould be le f t out of thef r amew ork e ntire ly. • N ote tha t the user inter fa c e would ha ve to be provided, but w ould proba bly not ac tua lly a ppe ar a s slots in the ba sicsystem; theuserinte r fa cewould be asepa ra tesubsystem that would simply c a ll the ser vic es. iii. Hooks (pla c es w her e optional a dd- ons c an ea sily be plugged in) • A bility to ma na ge additional type s of inf or ma tion a bout fr equent f lier s ( e.g. wor k addre ss, e ma il,), beyond the ba sic minimum inf or mation. Dif fe re nt air line s might wa nt to ke ep diff e re nt kinds of inf or mation f oruse in ma r ke ting etc . • A bility to ha vediff er e nt c lasse s of use rs (e .g. pre stigeuser s w ho ha veac cumulate d la r genumber s of points) • Mec ha nism to de lete a cc ounts a f te r ac er tain time per iod w ith no a ctivity ( this might bea c tiva ted by themonthly r un that pr ints re por ts) • A bility to a dd diff e re nt kinds of points to be use d for dif f er ent pur poses (e .g. some a ir lines, in a ddition to mile s, a lso ke ep tr ac k of a separ a tec ount of miles f low n in fir st c lass; such points might have dif fe r ent r ules, suc h a s e xpir ing a f te r thee nd ofa ye a r) . E 3.7 p. 70 Ev aluating whe the r or not oneshould first de ve lop a fram eworkwhen de signing an applic ation. a )* A r gume nts in favour ofde ve loping af ull f re que nt flie rf ra mew or k: • D e ve loping thef r amew ork impr ove s your ove ra ll de sign. Sinc e you w ould have to build f lexibility into the f ra me w or k to allowit to be use d by othe r s, you would be ne fit f rom tha t f le xibility w hen you ha ve to ma ke c ha nge s yourself . • A s a c onse que nc eof thea bove , you would e xpe ct ma inte nance costs to be re duc ed; you would a lso e xpe ct to beableto r e spond f asterto mar ket-dr iven re quire me nts c hange s. • Y ou might be able to se ll your fr ame work to othe rs, or to pr ovide fr equent- f lier se rvice s to other smalle r a ir lines. • Should two airline s using the same f ra me w or k dec ide to w or k together in a n a llia nce ( or to me rge ) the ir syste ms would bemor ec ompatible with ea c h other , r educ ing c osts. E 3.8 p.74 E valuating whether an applic ation should bede signe d as a client- serve r systemor not. a )*Wor d proce ssors ar e not normally de signe d using a c lient-ser vera r chite ctur e . Thef ollow ing a re some of ther e asons w hy not: • Peopletypica lly use word pr oc essor s on la ptop compute r s orothe rmac hines that ma y not bec onnec te d to any netw or k. • A lthough pe ople do shar e w or d- proce sse d data, most pe ople wor k on their own loca l c opy a nd then sha reit w hen they a r e finishe d. I t might bebene ficia l to allowaw or d proc essorto optionally conne ct to ase rver to do suc h things a s loa d a nd sa ve da ta , or to enable tw o people to e dit the sa me document c oncur re ntly. H owe ve r it w ould still be nec essar y to ensur e tha t theuserc ould ope ra te theprogra m w hilenot c onne c te d
PUBLIC ANSWERS TO EXERCISES E3. 9 p 74 Determining the services to be provided by a server. a)*An airline reservation server would be expected to do some of the following activities Maintain the list of flights along with basic details of each flight(and allow changes) Maintain the pnces(and allow changes, special offers etc. Maintain the bookings(allow bookings to be made, changed and deleted) Allow people to query all of the above E3.10 P. 79 Evaluating the balance of work on the client and server side of a system a)* For an airline reservation system 1. Server work: See exercise E3.9 ii. Client work. Enter queries about available flights and display the results Display and print itineraries iii Information transmitted from server to client Results of queries(relatively simple text) iv: Information transmitted from client to server: Simple commands and their arguments v: How the client's work could be minimized or maximized The client might be interacting with several different reservation systems, producing overall itineraries that would combine the results from several servers. A server could be developed to provide this function -interacting with other servers and managing itineraries The client could, on the other hand, be given a lot of intelligence to work out itineraries and good deals. It could find the best prices, and even run a bidding mechanism that would try to get airline servers to give better deals The client could simply be a web browser with no intelligence at all about the frequent flier domain vi: Network effects of changing the client's workload Putting more intelligence into the server(such as having the server interact with other servers) would have only a moderate effect on the quantity of information transmitted in the network as a whole Adding extra intelligence to the client might result in large numbers of queries being transmitted, and large numbers of replies returned. The client would need to perform these queries in order to marshal the information it needs to make decisions laving the client become nothing more than a web browser, would probably increase netw traffic from the server to the client, since now the server would have to transmit images and all other information that will make the ui of the client look nice E3. 11 p. 80 Writing protocols for a client-server system There are clearly many possible protocols for these systems, the level of complexity could become substantial the following shows some basic sets of messages that could be exchanged a)*Airline reservation system. Note that a real system can be extremely complex; the following represents a simplified view of the kinds of messages that such a system would need to exchange Messages to server Possible replies to client addRegularFlight number plane Type effective Date confirmFlightAdded number flightNumberAlready Exists addFlightLeg flightNumber origin leave Time destination arrive Time confirmLegAdded flightTimeConflictsWithAnotherLeg deleteRegularFlight number effective date confirmDeletion flightNumberDoesNotExist C 2002 TIMOTHY C. LETHBRIDGE AND ROBERT LAGANIERE
PA9 PUBLI C A NSW ERS T O EX E RCISE S © 2002 T IMO TH Y C. LE T HBRI D GEA N D RO BERT L AG AN I ÈRE E 3.9 p.74 D eterm ining these rv ice s to beprov ide d by a serve r. a )*A n air line re ser vat ion ser ve r would be e xpec ted to do some of thef ollow ing a ctivitie s: • Mainta in the list off lights along w ith ba sic details ofea ch flight (a nd allowc hange s) • Mainta in the pr ice s ( and a llowchanges, spe cia l of f er s e tc .) • Mainta in the bookings ( allowbookings to bema de , c ha nge d and dele te d) • A llowpe ople to quer y a ll ofthe above E 3.10 p. 79 Ev aluating thebalanceof work on thec lie nt and serve r sideof a system . a )*F oran air line r eser vat ion syst em : i. Ser ve rw or k: Se ee xe r ciseE3.9. ii. Client w or k: • E nterque rie s about a vaila blef lights a nd display the re sults. • E nterbookings • D ispla y and print itine ra r ie s iii. I nf or mation tra nsmitted f r om se rverto c lie nt: • Results ofquer ies ( r elative ly simple te xt) iv: I nf or mation tra nsmitted f r om c lie nt to se rve r: • Simplec ommands and the irar guments. v: H owthe client’ s w or k c ould beminimiz ed orma ximiz ed: • T he c lie nt might be inter a cting w ith seve ra l dif fe r ent r eser vation systems, pr oducing over a ll itine r ar ie s tha t w ould combine the r esults fr om se ver al se rve rs. A ser ver c ould be de velope d to provide this function – inte ra c ting with othe rser ver s a nd ma na ging itine ra r ie s. • T hec lie nt could, on the other ha nd, be given a lot of ‘ inte llige nce ’ to wor k out itiner ar ies a nd ‘good dea ls’ . It could f ind the be st pr ic e s, a nd eve n run a bidding mec hanism tha t w ould tr y to get a irline ser ve r s to givebe tte r de a ls. • T hec lie nt could simply beaw e b br owserwith no inte llige nc ea t a ll a bout thef r eque nt flierdoma in. vi: N etwor k ef f ec ts ofc hanging the c lie nt’s workloa d: • Putting mor e intelligence into the ser ve r ( suc h as ha ving the ser ver inte ra c t with other se rver s) w ould ha ve only a moder ate e ff e ct on the quantity of inf or ma tion tra nsmitte d in the ne tw or k a s a w hole . • A dding e xtr a intelligenc e to the c lient might re sult in la r ge number s of que rie s be ing tr ansmitted, a nd la rge numbe r s of re plies r e turne d. T he client w ould ne ed to pe rf or m the se que ries in or de r to mar sha l theinf ormation it nee ds to ma kede cisions. • H aving the clie nt be come nothing more than a we b browse r, w ould proba bly incr ea se ne twork tra ff ic fr om theser ver to the clie nt, sinc e now the se r ve r w ould ha ve to tr ansmit ima ge s a nd a ll the otherinfor ma tion tha t will ma ke theU I of thec lie nt look nice . E 3.11 p. 80 Writing protoc ols for a c lient-serv er sy stem . T he rear e c le ar ly ma ny possibleprotoc ols f orthesesystems; the level ofc omple xity c ould be come substantia l. thef ollow ing show s some basicse ts ofme ssage s tha t could be e xc hange d. a )*A ir line re ser vat ion syste m . N otetha t ar e al system ca n be extre me ly complex; the following re pr e se nts a simplified viewofthe kinds ofmessages that such a syste m w ould ne ed to e xchange. M essages t o ser ver P ossibler e plie s t o c lient • addRegularFlight num be r planeType e ffe ctiv e Date confirmFlightAdded numbe r flightNumberAlreadyExists • addFlightLeg flightNumbe r origin leave Tim e destination arrive Tim e confirmLegAdded flightTimeConflictsWithAnotherLeg • deleteRegularFlight num be r e ffe ctiv e Date confirmDeletion flightNumberDoesNotExist
PUBLIC ANSWERS TO EXERCISES addFareclass fare Code confirmfareclass fareClassAlready present setFare origin destination class Code start Date enddate firmA addBooking name date flight originCity destination City fareClass confirmBooking confirmation Number seat bookingcannotBeMade reason deleteBooking confirmation Number f bookingNotcancelled reason confirmationNumber Invalid queryFlightAvailability date origin destination fare Class earliestDeplime latestArrTime availableFlight date flightNumber fareClass noMatchingAvailableFlight queryBookings name date confirmBooking confirmationNumber seat query BookingsByNumber confirmationNumber booking Info flightNumber date name origin destination fare Class seat queryPassengers flightNumber date bookingInfo flightNumber date name origin destination fare Class seat THESE ANSWERS SUPPORT THE BOOK OBJECT ORIENTED SOFTWARE ENGINEERING
PUBLI C A NSW ERS T O EX E RCISE S PA10 T HE SEAN SW E RS SU PPORTT HEBO OK O BJ ECT O RI E NTEDSO FTW AR E E NG INE ER ING : • addFareClass fareCode confirmFareClass fareClassAlreadyPresent • setFare origin destination c lassCode startD atee ndD ate confirmFare • addBooking nam e date flight originCity de stinationCityfare Class confirmBooking c onfirmationNum ber se at bookingCannotBeMade reason • deleteBooking c onfirmationNum ber confirmBookingDeletion bookingNotCancelled reason confirmationNumberInvalid • queryFlightAvailability date origin destination fare Class e arlie stD epTim e latestArrTime availableFlight da teflightN umberf a re Cla ss noMatchingAvailableFlight • queryBookings nam e date confirmBooking c onfirmationNum ber se at • queryBookingsByNumber c onfirmationNum ber bookingInfo flightNumbe r date nam e origin destination fare Class seat • queryPassengers flightNumbe r date bookingInfo flightNumbe r date nam e origin destination fare Class seat