Writing Inter Class constraints [message #725623] |
Thu, 15 September 2011 07:22  |
Eclipse User |
|
|
|
Hello,
Is it possible to write interclass constraints ?
For example,
If I have a parent A, with attributes birth date, death (suppose Int for simplicity)
and 3 children of that class
A<>---B (relation name childone)
A<>---C (relation name childtwo)
A<>---D (relation name childthree)
now i want to write some constraints that make sure that
B is born after A
C is born after B dies
D is born after C dies ?
So, is something like the following possible :
context A
inv :
childone -> forAll (b:B |
b:birthdate.after(a.birthdate)
context A
inv :
childtwo -> forAll (c:C |
c:birthdate.after(b.death)
context A
inv :
childthree -> forAll (d:D |
d:birthdate.after(c.death)
And also, If it is correct, should I write these constraints in individual nodes like B,C,D or write them for the parent class A?
Thanks is advance
Ph.
|
|
|
|
Re: Writing Inter Class constraints [message #725732 is a reply to message #725623] |
Thu, 15 September 2011 11:51   |
Eclipse User |
|
|
|
Hi
Of course you can write interclass constraints; it would be very very
limiting if you couldn't.
However your examples seem to risk confusing classes with instances.
Where you place constraints is a matter of style, but simpler is usually
better. A forAll is a hint that yiour locality may be inefficient.
I would write something like
context Person:
inv CausalLife: birthdate <= death
inv CausalAncestry: parent.birthdate <= birthdate and birthdate <=
parent.death
Regards
Ed Willink
On 15/09/2011 12:22, Phoenix wrote:
> Hello,
>
> Is it possible to write interclass constraints ?
>
> For example,
>
> If I have a parent A, with attributes birth date, death (suppose Int
> for simplicity)
> and 3 children of that class
> A<>---B (relation name childone)
> A<>---C (relation name childtwo)
> A<>---D (relation name childthree)
> now i want to write some constraints that make sure that
>
> B is born after A
> C is born after B dies
> D is born after C dies ?
>
>
>
> So, is something like the following possible :
>
> context A
> inv :
> childone -> forAll (b:B |
> b:birthdate.after(a.birthdate)
>
> context A
> inv :
> childtwo -> forAll (c:C |
> c:birthdate.after(b.death)
>
> context A
> inv :
> childthree -> forAll (d:D |
> d:birthdate.after(c.death)
>
>
> And also, If it is correct, should I write these constraints in
> individual nodes like B,C,D or write them for the parent class A?
>
> Thanks is advance
> Ph.
>
|
|
|
Re: Writing Inter Class constraints [message #725733 is a reply to message #725630] |
Thu, 15 September 2011 11:53  |
Eclipse User |
|
|
|
Hi
OCL expresses constraints, so OCL can provide a validation constraint on
three children. But
OCL is almost useless by itself. OCL must be embedded in some context
that provides models. It is that context that must evaluate the
condition as part of "allowed to add".
Regards
Ed Willink
On 15/09/2011 12:38, Phoenix wrote:
> Also, is it possible that I make sure the User is allowed to add only
> these three children for A ?
|
|
|
Powered by
FUDForum. Page generated in 1.04605 seconds