Writing Inter Class constraints [message #725623] |
Thu, 15 September 2011 11:22 |
Phoenix Messages: 10 Registered: September 2011 |
Junior Member |
|
|
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 15:51 |
Ed Willink Messages: 7681 Registered: July 2009 |
Senior Member |
|
|
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.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04375 seconds