Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Writing Inter Class constraints
Writing Inter Class constraints [message #725623] Thu, 15 September 2011 11:22 Go to next message
Phoenix  is currently offline Phoenix Friend
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 #725630 is a reply to message #725623] Thu, 15 September 2011 11:38 Go to previous messageGo to next message
Phoenix  is currently offline Phoenix Friend
Messages: 10
Registered: September 2011
Junior Member
Also, is it possible that I make sure the User is allowed to add only these three children for A ?
Re: Writing Inter Class constraints [message #725732 is a reply to message #725623] Thu, 15 September 2011 15:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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.
>
Re: Writing Inter Class constraints [message #725733 is a reply to message #725630] Thu, 15 September 2011 15:53 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 ?
Previous Topic:A Parser For a Specific Model
Next Topic:OCL for InstanceSpecifications on M1
Goto Forum:
  


Current Time: Thu Apr 25 01:23:45 GMT 2024

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

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

Back to the top