Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Cardinality constraint for non-navigable associations ?
Cardinality constraint for non-navigable associations ? [message #49110] Sat, 19 January 2008 18:05 Go to next message
Eclipse UserFriend
Originally posted by: maiera.de.ibm.com

We are using non-navigable associations (the ends are owned by the
association class) and we have situations, where we want to specify an
OCL constraint (at the model level) on the cardinality of an end. For
specific reasons, we cannot use the cardinality definition of the end
itself, it really has to be a constraint.

Let's assume we have classes C1 and C2, and association A1 with ends c1
referencing class C1 and c2 referencing class C2.

Let's further assume the constraint to be specified is the equivalent of
a cardinality of 1 on end c1, i.e. each instance of C2 is associated via
A1 to exactly one instance of C1.

I think I understand how to specify such a constraint if c1 is navigable
(i.e. c1 is owned by class C2):

Constraint on class C2:
inv: self.c1->size()=1

I interpret this OCL to apply for each instance of the class it is
defined on, in this case each instance of C2. This to me seems to be
expressing exactly the intended constraint: For each instance of C2, the
number of occurences of its owned end c1 is exactly 1.

Now if c1 is non-navigable, I have difficulties to come up with the
corresponding OCL statement, nor do I even understand on which object
the constraint should be defined.

It seems to me that I still need to define the constraint on class C2.,
because I want to make a statement that is supposed to apply to each
instance of C2, but there is no end c1 anymore in the scope of class C2
(since it is now owned by the association A1).

The constraint on association A1:
inv: self.c1->size()=1
does not seem to express the intended constraint, because it says that
for each instance of A1, its end c1 has to have exactly one occurence.
That is always the case, because each instance of A1 always references
only one instance of each end, regardless of any cardinality constraints.

Question: What is the right way to express a cardinality constraint for
non-navigable ends ?

Andy
Re: Cardinality constraint for non-navigable associations ? [message #49215 is a reply to message #49110] Mon, 21 January 2008 14:16 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Andy,

Regardless of end ownership or navigability, the multiplicity declared by an
association end always constrains the cardinality from the perspective of
the classifiers at the association ends.

Thus, even in your association that owns both of its ends (and perhaps they
aren't navigable, either), "c1 [1]" indicates that for any C2, exactly one
C1 is linked to it.

OCL has the power to navigate non-navigable association ends, even unowned,
so you could alternatively do:

context C2
self.c1->size() = 1

exactly as you suggested for the navigable case. This depends, of course,
on the name "c1" not otherwise being used for a property in the C2
namespace.

MDT OCL's UML binding actually supports evaluation of this kind of
navigation of non-navigable association ends, for models generated to code
from UML2. And since 1.2 M3, we even support navigation of unnamed (and
non-navigable) ends; see the N&N page for details:

http://wiki.eclipse.org/MDT_1.1_New_and_Noteworthy#Navigatio n_of_Unnamed_Association_Ends

HTH,

Christian


Andreas Maier wrote:

> We are using non-navigable associations (the ends are owned by the
> association class) and we have situations, where we want to specify an
> OCL constraint (at the model level) on the cardinality of an end. For
> specific reasons, we cannot use the cardinality definition of the end
> itself, it really has to be a constraint.
>
> Let's assume we have classes C1 and C2, and association A1 with ends c1
> referencing class C1 and c2 referencing class C2.
>
> Let's further assume the constraint to be specified is the equivalent of
> a cardinality of 1 on end c1, i.e. each instance of C2 is associated via
> A1 to exactly one instance of C1.
>
> I think I understand how to specify such a constraint if c1 is navigable
> (i.e. c1 is owned by class C2):
>
> Constraint on class C2:
> inv: self.c1->size()=1
>
> I interpret this OCL to apply for each instance of the class it is
> defined on, in this case each instance of C2. This to me seems to be
> expressing exactly the intended constraint: For each instance of C2, the
> number of occurences of its owned end c1 is exactly 1.
>
> Now if c1 is non-navigable, I have difficulties to come up with the
> corresponding OCL statement, nor do I even understand on which object
> the constraint should be defined.
>
> It seems to me that I still need to define the constraint on class C2.,
> because I want to make a statement that is supposed to apply to each
> instance of C2, but there is no end c1 anymore in the scope of class C2
> (since it is now owned by the association A1).
>
> The constraint on association A1:
> inv: self.c1->size()=1
> does not seem to express the intended constraint, because it says that
> for each instance of A1, its end c1 has to have exactly one occurence.
> That is always the case, because each instance of A1 always references
> only one instance of each end, regardless of any cardinality constraints.
>
> Question: What is the right way to express a cardinality constraint for
> non-navigable ends ?
>
> Andy
Previous Topic:SimpleAnyType
Next Topic:How to access operation parameters in OCL
Goto Forum:
  


Current Time: Wed Sep 25 22:48:09 GMT 2024

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

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

Back to the top