{"id":108,"date":"2004-04-30T14:50:18","date_gmt":"2004-04-30T04:50:18","guid":{"rendered":"http:\/\/www.malcolmgroves.com\/blog\/?p=108"},"modified":"2004-04-30T14:50:18","modified_gmt":"2004-04-30T04:50:18","slug":"derived-associations","status":"publish","type":"post","link":"http:\/\/www.malcolmgroves.com\/blog\/?p=108","title":{"rendered":"Derived Associations"},"content":{"rendered":"<p>OK, we&#8217;ve spent the last few days in the model, talking about Packages, and all sorts of Derived Attributes. I want to spend a bit more time in this area, specifically on Derived Associations and Association Classes, then we&#8217;ll head off to other areas such as Persistence and Optimistic Locking, before starting to look at UI stuff. Feel free to let me know other areas you&#8217;d like to see covered.<\/p>\n<p>OK, let&#8217;s look at Derived Associations. I&#8217;m assuming you&#8217;ve worked through the <a href=\"http:\/\/www.borland.com\/delphi_net\/architect\/eco\/tutorial\/\">ECO Tutorial<\/a> on <a href=\"http:\/\/www.borland.com\/delphi_net\/architect\/eco\/tutorial\/tutorial2.html\">Associations<\/a>, or at the very least have created a few associations in ECO before. I won&#8217;t be covering the same territory here. If you&#8217;re not comfortable creating associations and what all the bits like Multiplicity mean, then off you go, this&#8217;ll still be here when you get back.<\/p>\n<p>Look at the model below. I&#8217;m trying to stick with the same type of problem domain for a few articles, so this is still in the realm of Appointments (albeit cleaned up a little, just to keep it simple).<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.malcolmgroves.com\/images\/2004\/04\/30\/20040430001.gif\" \/><\/p>\n<p>We have a Person class and an Appointment class, with an association between them where an Appointment can belong to only one Person, and a Person can have zero to many Appointments. Note however, that the Appointment has a Confirmed attribute. You may decide that you need to deal with only confirmed appointments so often, that you want another association between these two classes that only displays appointments that have the Confirmed attribute set. <\/p>\n<p>However, this isn&#8217;t really a new association, as it should be possible to calculate the collection of confirmed appointments from our existing association. If you&#8217;re thinking that kinda sounds like Derived Attributes, you&#8217;d be right. We can define a new association, that doesn&#8217;t get persisted to the database, but exists in our model. We use OCL to derive the collection of Appointments we want to appear as part of this association.<\/p>\n<p>So, in the model below, I&#8217;ve added a new association between the two classes. You define the association pretty much the same way you define any association. However, note I&#8217;ve set it to be a one way association (by setting the Navigable property on the Appointment end (End2) to False). This association is for navigating from the Person down to the Appointment. In this scenario we can still use our existing association to get from the Appointment back up to the Person. Whether an Appointment is confirmed or not does not change the Person who owns it.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.malcolmgroves.com\/images\/2004\/04\/30\/20040430002.gif\" \/><\/p>\n<p>Note I&#8217;ve also set the derived property to True, and the Persistence property to Transient. Lastly I&#8217;ve specified some OCL in the DerivationOCL property. This is the OCL that is going to determine which Appointment objects appear as part of this association:<\/p>\n<p>Appointments-&gt;select(Confirmed)<\/p>\n<p>This is basically saying, from all Appointments associated with this Person, select the subset where the Confirmed attribute is True. <\/p>\n<p>The screen shot below shows the two associations at runtime. Person.Appointments shows all appointments for a specific person (the second grid from the top), while Person.ConfirmedAppointments (the bottom grid) shows only those appointments for a specific Person that have the Confirmed attribute set to True.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.malcolmgroves.com\/images\/2004\/04\/30\/20040430003.gif\" \/><\/p>\n<p>&#160;<\/p>\n<div class=\"wlWriterSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2ad6c65f-dcf8-4701-aaf8-a27aa408e22d\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/Delphi\" rel=\"tag\">Delphi<\/a>,<a href=\"http:\/\/technorati.com\/tags\/ECO\" rel=\"tag\">ECO<\/a>,<a href=\"http:\/\/technorati.com\/tags\/OCL\" rel=\"tag\">OCL<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>OK, we&#8217;ve spent the last few days in the model, talking about Packages, and all sorts of Derived Attributes. I want to spend a bit more time in this area, specifically on Derived Associations and Association Classes, then we&#8217;ll head off to other areas such as Persistence and Optimistic Locking, before starting to look at [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=108"}],"version-history":[{"count":0,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}