Vitavonni

Fri, 12 May 2006

A bug in the UML 2.0 OCL spec?

I think I've found a bug in the UML 2.0 OCL spec.

It's actually a well-known issue for C++, documented e.g. in the C++ FAQ.

It's not so obvious in Java, since Java didn't have Templates for a long time.

The UML 2.0 OCL spec says on page A-22, Definition A.27 (Type Hierarchy)

If t' ≤ t then Set(t') ≤ Set(t)
With ≤ having the meaning "conforms to" for types.
[Update: newer UML 2.0 OCL document, the latest I could find, page 38 still says the same]

Any good C++ programmer should know that this doesn't work. From the C++ FAQ "Is a parking-lot-of-Car a kind-of parking-lot-of-Vehicle?":

"A Bag-of-Apple is not a kind-of Bag-of-Fruit." If a Bag-of-Apple could be passed as a Bag-of-Fruit, someone could put a Banana into the Bag, even though it is supposed to only contain Apples!

Note that the converse, Set(t) ≤ Set(t'), also doesn't hold. While you can put Apples into a Bag-of-Fruit just fine, you may still find a Banana in there.

This has an obvious reason: when passing data to the object it can be "downcasted", and when retrieving data it can be "downcasted", too. But it can never be upcasted.

This should occur in OCL, too. A "Set(Apple)" doesn't conform to "Set(Fruit)" by the usual interpretations that I can call "put(Banana)" on any "Set(Fruit)"!

Can anyone enlight me, if this really is a bug in the OCL spec, maybe has already been corrected, or if there is some magic in OCLs definition of "conforms to" or interfaces that solves this problem?

(Yes, I think there might be something in OCL that solves this problem, for example if this hierarchy is only used in condition checking, then in fact all operations are "get" operations... but I've just started reading on OCL, I don't know much about its expressiveness yet...)

[Update: Onne Gorter has some good thoughts on this. He basically notes that this is not a problem if you don't have any references to the "uncasted" list. For example if the cast is a function like in a functional language that actually returns a new set. I'll have to consider this for OCL, but given that OCL and UML are somewhat designed for Java - and Java suffers from this problem, too - I'm not so sure about it.]

[category: /en | Permalink]
Menu
[planet.debian]
[planet.xmlhack]
[planet SELinux]
[munichblogs]
[email]
[RSS 2 feed]
[English RSS 2]
Categories
< May 2006 >
SuMoTuWeThFrSa
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
28293031   
Archives
2010-Jul
2010-Jun
2010-May
2010-Apr
2010-Mar
2010-Feb
2010-Jan
2009-Dec
2009-Nov
2009-Oct
2009-Sep
2009-Aug
2009-Jul
2009-Jun
2009-May
2009-Apr
2009-Mar
2009-Feb
2009-Jan
2008-Dec
2008-Nov
2008-Oct
2008-Sep
2008-Aug
2008-Jul
2008-May
2008-Apr
2008-Mar
2008-Feb
2008-Jan
2007-Dec
2007-Nov
2007-Oct
2007-Sep
2007-Aug
2007-Jul
2007-Jun
2007-May
2007-Apr
2007-Mar
2007-Feb
2007-Jan
2006-Dec
2006-Nov
2006-Oct
2006-Sep
2006-Aug
2006-Jul
2006-Jun
2006-May
2006-Apr
2006-Mar
2006-Feb
2006-Jan
2005-Dec
2005-Nov
2005-Oct
2005-Sep
2005-Aug
2005-Jul
2005-Jun
2005-May
2005-Apr
2005-Mar
2005-Feb
2005-Jan
2004-Dec
2004-Nov
2004-Oct
2004-Sep
2004-Aug
2004-Jul
Other links:
Swing and the City - Lindy Hop in Munich