Re: Object Constraint Language and Inheritance



Hi,
Ulrich Frank <franku@xxxxxxxxxxxxxxxxx> schrieb:

context A
inv: self.allInstancesOf()->forall(c | c.oclIsTypeOf(A))

I question myself if that is right. A should have no subclass but a
possible subclass should be B. When I regard to object oriented
programming every B-subobject is also an A. So if you type
'c.oclIsTypeOf(A)' and c is an B-Subobject then of couse c is also of
type A. If so this would not prohibit that A cannot have subclasses.
Right?

OCL has a "fussy" type test, i.e., oclIsType() ("is it exactly the
given type), and a "sloppy" one, i.e., oclIsKindOf() ("is it of the
given type or a subtype"). For example, these a described on page 133 of the
"UML OCL 2.0 Adopted Specification" (OMG document 03-10-14).

Thus, if we have a class A with subclass B and let a:A be a instance
of A and b:B an instance of B then (excuse the sloppy notation):

- a.oclIsTypeOf(A) evaluates to true
- a.oclIsKindOf(A) evaluates to true
- a.oclIsTypeOf(B) evaluates to false
- a.oclIsKindOf(B) evaluates to false

- b.oclIsTypeOf(A) evaluates to false
- b.oclIsKindOf(A) evaluates to true
- b.oclIsTypeOf(B) evaluates to true
- b.oclIsKindOf(B) evaluates to true


Does this help? If not, can you please explain in a little more detail
which property you want to specify (you can also mail me privately, if
you wish)?

Achim





.