正在加载图片...
PA15 PUBLIC ANSWERS TO EXERCISES E56 No public answer E5. 7 No public answer E5. 8 No public answer E59 No public answer E5. 10 No public answer E5. 11 No public answer E5.12 p 175-176 Writing OCL constraints a) *Referring to Figure 5.11, p. 164 context Recordingcategory inv: subcategory->forAll(r I self<> r 13 p. 178 Designing how operations would be performed a) *In this example it is ambiguous whether getsiblings should include half siblings or just full siblings: we assume the former getsiblings(a method of Person) would be performed as follows I Obtain the parents(a Union), by following the association 2. For the femalePartner of the Union 2.1 For each of her Unions 2.1.1 Put the children of the Union in the result set (excluding duplicates and the self object) 3. Repeat step 2 for the malePartner 4 Return the result c)* Step siblings are children of a persons step-parent which are not half-siblings. To solve this problem we will first define a method of Person called getstepParents, as follows 1. Obtain the parents(a Union we will call mainUnion) 2. For the femalepartner of the mainUnion 2.1 For each of her Unions other than the mainUnion 2.1.1 Put the malePartner in the result set 3. Repeat step 2 inverting femalePartner and malePartner 4 Return the result Now we can define the getstepsiblings method of person 1. For each stepParent obtained by calling getstepParents 1. 1 Add each of the children of the stepParent to the result set 2. Call getsiblings to obtain the set of siblings 3. Subtract the siblings and self from the result set 4. Return the result set E5.14 p. 178 Writing OCL constraints for the genealogical example a)"context Person in dateofDeath or dateofBirth in or dateofBirth < dateofDeath E5. 15 No public answer E5. 16 No public answer E5. 17 No public answer C 2002 TIMOTHY C. LETHBRIDGE AND ROBERT LAGANIEREPA15 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 5.6 No public answe r E 5.7 No public answe r E 5.8 No public answe r E 5.9 No public answe r E 5.10 No public answe r E 5.11 No public answe r E 5.12 p. 175-176 Writing O CL constraints. a )*Ref er r ing to Figur e 5.11, p. 164 context RecordingCategory inv: subcategory->forAll(r | self <> r) E 5.13 p. 178 D esigning how operations would bepe rform ed a )*I n this exa mple it is ambiguous whether getSiblings should inc lude ha lf siblings or just full siblings; w e assume thef ormer . getSiblings (ame thod of Person)w ould bepe rf ormed as f ollow s: 1 O btain the parents (a Union) , by following the a ssoc iation 2. Forthe femalePartner of the Union: 2.1 Fore a ch ofher Unions 2.1.1 Put the childr en ofthe Union in the re sult set ( excluding duplica te s a nd the self objec t) 3. Repea t ste p 2 f or the malePartner 4. Retur n there sult se t c )*Ste p siblings a r e childr en of a pe rson’ s ste p- par ent w hic h ar e not ha lf - siblings. To solve this proble m we w ill f ir st de fine a method of Person ca lle d getStepParents, a s f ollow s: 1. O btain thepa re nts ( a Union wew ill c a ll mainUnion) . 2. Forthe femalePartner of the mainUnion: 2.1 Fore a ch ofher Unions othe r tha n the mainUnion 2.1.1 Put the malePartner in the re sult set 3. Repea t ste p 2 inve rting femalePartner and malePartner 4. Retur n there sult se t N oww ec an de fine the getStepSiblings me thod of Person: 1. Fore a ch stepParent obta ine d by ca lling getStepParents 1.1 A dd e a ch ofthe childr en ofthe stepParent to the re sult set 2. Call getSiblings to obta in the set of siblings 3. Subtr a ct the siblings and self f rom ther e sult se t 4. Retur n there sult se t E 5.14 p. 178 W riting O CL c onstraints for thege ne alogical e xam ple. a )*context Person inv: dateOfDeath = ‘’ or dateOfBirth = ‘’ or dateOfBirth <= dateOfDeath E 5.15 No public answe r E 5.16 No public answe r E 5.17 No public answe r
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有