Skip to main content



      Home
Home » Modeling » OCL » OCL for UML AssociationClass
OCL for UML AssociationClass [message #40118] Tue, 09 October 2007 14:07 Go to next message
Eclipse UserFriend
A question for you OCL experts out there. How would I write an OCL
constraint, where the context is a Class and I need to constrain the value
of an AssociationClass attribute? Can this be written relative to the role
name of the navigable property at the destination end of the
AssociationClass?

Thanks,
Dave Carlson
Re: OCL for UML AssociationClass [message #40149 is a reply to message #40118] Tue, 09 October 2007 15:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Dave,

The member ends of AssociationClasses are navigated in the same fashion as
the member ends of Associations, so using that role name as you suggest
just navigates to the classifier at the other end.

The trick supplied by OCL is to use dot-navigation with the AssociationClass
name as a role name (lower-casing the initial letter (yes, that has l10n
issues)). For example, consider the following model:

Class Employee
name : String
bornOn : Date
employer : Company

Class Company
name : String
incorporatedOn : Date
employee[0..*] : Employee

AssociationClass Job
[ member-end ] Employee::employer
[ member-end ] Company::employee
startOn : Date
salary : Real

You can formulate OCL constraints such as

context Employee
inv sane_start_dates: self.job->forAll(startOn > self.bornOn)

Also, the member ends of the association class can be navigated from its
context and are treated as scalar (multiplicity 1) regardless of their
actual definition:

context Job
inv sane_start_date: self.startOn > self.employee.bornOn

context Company
inv sane_start_dates: self.job->forAll(j | j.startOn > j.employee.bornOn)

Cheers,

Christian

Dave Carlson wrote:

> A question for you OCL experts out there. How would I write an OCL
> constraint, where the context is a Class and I need to constrain the value
> of an AssociationClass attribute? Can this be written relative to the
> role name of the navigable property at the destination end of the
> AssociationClass?
>
> Thanks,
> Dave Carlson
Re: OCL for UML AssociationClass [message #40179 is a reply to message #40149] Tue, 09 October 2007 18:54 Go to previous message
Eclipse UserFriend
Excellent, thanks Christian. I tried this out in a model using RSM and the
OCL editor recognizes these expressions.

"Christian W. Damus" <cdamus@ca.ibm.com> wrote in message
news:fegmhd$5et$1@build.eclipse.org...
> Hi, Dave,
>
> The member ends of AssociationClasses are navigated in the same fashion as
> the member ends of Associations, so using that role name as you suggest
> just navigates to the classifier at the other end.
Previous Topic:Preconditions and inheritance
Next Topic:Ease of Use of OCL in EMF
Goto Forum:
  


Current Time: Thu Apr 17 22:02:35 EDT 2025

Powered by FUDForum. Page generated in 0.03286 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top