StudentAnswersChapter05Word文档下载推荐.docx
《StudentAnswersChapter05Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《StudentAnswersChapter05Word文档下载推荐.docx(7页珍藏版)》请在冰点文库上搜索。
Asitisresponsibleformaintainingdata,itmightbearguedthattheentitystereotypewasappropriate.Thisstereotypeisnormallyusedfordatainthesystemthatrepresentsasingleexternalentity,however.Therestaurantobjectdoesnotrepresentanentityinthissense,however,butinsteadmakesotherentitiesavailableinthesystem.Theentitystereotypeisprobablynotappropriatefortherestaurantobject,therefore.
Thereisacontrolaspecttotherestaurantobject,asitiscontrollingaccesstotheentitydataheldbythesystem.Thisismoreaquestionofbeinga`gatekeeper'
tosomesystemresourcesthancontrollinganumberofinteractions,asthebookingsystemobjectdoes,anditisprobablyclearernottorepresentbothbythesamestereotype.
Itthereforeappearsthatnoneoftheanalysisclassstereotypesstraightforwardlyappliestotherestaurantobject,andithasbeenleftinFigure5.4asaplainobject.
SuggestedanswerforExercise5.2
Thedateattributeinthebookingsystemclassrepresentsthedateforwhichbookinginformationiscurrentlybeingdisplayedbythesystem.Thedateattributeinthe`current'
bookingsshouldbethesameasthis,therefore,otherwisethesystemwillbedisplayingbookingsforthewrongdate.Thiscanbespecifiedbyaconstraintonthe`current'
associationasshownbelow.
SuggestedanswerforExercise5.3
Onthefaceofit,thisproposalmightseemtobeattractiveonthegroundsofremovingredundancy,followingtheguidelinethatdatashouldnotbestoredinmorethanoneplace.However,removingthedateattributefromthebookingsystemobjectwouldcreateproblemsinthesituationwheretherearenobookingsyetrecordedforadatethesystemisaskedtodisplay.Inthiscase,thesystemwouldhavenorecordofwhatdatewascurrentlybeingdisplayed.Ifawalk-inbookingwasthencreated,forexample,itwouldbedifficulttoworkoutthedaterequiredforthenewbookingobject.
Thissuggeststhatstoringthedateinbothclassesisnotinfactredundant,asthetwooccurrencesoftheattributehavedifferentsemantics,onereferringtothedatebeingdisplayedbythesystem,andtheothertothedateofanindividualbooking.Incaseslikethis,careneedstobetakenbefore`optimizing'
oneoftheattributesaway.
SuggestedanswerforExercise5.4
Producingarealizationforthisscenarioinvolvesdecidingwhichobjectisresponsiblefordetectingthatthedateisinvalid.Areasonableguidelinetoadopthereistovalidateuser-entereddataassoonaspossible.Thiswouldmeanthatthebookingsystemobjectshouldberesponsiblefordetectingerrors,andsoarealizationmightbeasfollows.
Therestaurantandbookingobjectshavebeenleftonthisdiagramtoemphasizethattheydonotreceiveanymessagesinthecourseofthisinteraction.Itisnotnecessaryatthislevelofdetailtoattempttospecifyhowthesystemreportstheerrortotheuserandrequestsreentryofthedate.Wecansimplyassumethatwhentheuserreentersthedateanewsystemmessagewillbegenerated,andeithertheinteractionaboveortheoneinFigure5.5willtakeplaceagain.
SuggestedanswerforExercise5.5
Thecompletesequencediagramisshownbelow.
SuggestedanswerforExercise5.6
Thesequencediagramfor`Recordwalk-in'
isshownbelow.Apartfromchangingtheactor,classandoperationnamesthroughouttorefertowalk-ins,themostsignificantchangeisthatacustomerobjectdoesnotneedtobelocated.Detailsreferringtocustomershavethereforebeenremovedfromthediagram.
SuggestedanswerforExercise5.7
Arealizationforthecasewherethecustomerisalreadyknowntothesystemisshowninthediagrambelow.AsinFigure5.5,therestaurantobjectretrievesdatafromcustomerobjectstocomparewiththenameandphonenumberoftherequestedcustomer.Assumingthatamatchisfound,acustomerobjectisreturnedtothecaller.
Inthecasewherenomatchingcustomerisfound,anewinstanceiscreatedandareferencetoitisreturnedtothecaller,asshownbelow.
SuggestedanswerforExercise5.8
Apossiblesequencediagramfortabletransferisshownbelow.Therequiredtableisfirstselected,asshowninFigures5.9and5.11.Thenthetableobjectcorrespondingtothenumberofthenewtableisretrievedfromtherestaurantobject,asinFigure5.8.Finally,thetableallocatedtotheselectedbookingisupdated,andthedisplayrefreshed.
Analternativedesignmightpassthetablenumbertotheselectedbooking,whichwouldthenhavetoretrievetherequiredtableobjectfromtherestaurantitself.Thisdesignisslightlymore`decentralized'
thantheoneabove,butontheotherhandintroducesacirculardependencybetweenthebookingandrestaurantclasses.Thedesignshownaboveisthereforeprobablypreferable.
SuggestedanswerforExercise5.9
ThediagramsbelowshowtheclassesfromFigure5.13withtypeinformationaddedtoattributesandoperations.TheadditionsarestrictlybasedonwhatisstatedinthevariousrealizationsgiveninChapter5,anddonotattempttodefinefinalsignaturesfortheoperations.Thiswillbeconsideredlaterwhenimplementingeachclass.
Wheredetailedparametershavenotyetbeendefined,typessuchasBookingIdandBookingDetailshavebeenusedasplaceholders.TheOCLcollectiontypeSet(T)hasbeenusedtoindicatethattheRestaurant.getBookingsoperationreturnsingeneralmorethanonebookingsobject.