init and derive constraints



Date view Thread view Subject view Author view Attachment view

From: Alexandre Correa (alc@wnetrj.com.br)
Date: Sat 26 Jun 2004 - 02:44:24 BST


Hi all,

I would like to share some doubts on the semantics of init and derive 
constraints and its effects on a class hierarchy.

Suppose you have the following class definitions:

class A
    attrib x : integer

class B is a subclass of class A
    attrib y : integer

 From my understanding of the OCL specification, you can only define a init 
value using class A definition, i.e.:
context A::x : integer
init: 10

This is also valid:
context B::y : integer
init: 20

But you cannot define something like this (even if the constraints above 
didn't exist):
context B::x : integer
init: 30

Now, suppose that A (as defined above) is an abstract class that has two 
subclasses (B and C). B was defined above and C is defined below:
class C is a subclass of class A
    attrib z : integer

Now I ask: What if I wanted to say that the initial value of x for B 
objects is 10 and the initial value of x for C objects is 20? Is it 
possible to express this in OCL using the current semantics? From my 
understanding of figure 32 on page 161 of the OCL 2 specification, it is not.

The discussion above may also be applied to derived values. Suppose that x 
is a derived attribute defined in A. How can I express that the derivation 
rule for B objects (B::x) is different from the derivation rule for C 
objects (C::x)?

Any thoughts are welcome...

Regards,
Alexandre Correa
Federal University of Rio de Janeiro

Date view Thread view Subject view Author view Attachment view