正在加载图片...
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 ENGINEERINGPUBLI 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
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有