It appears that my original statement of the problem was in error. A GM_Position should be a union between a DirectPosition (which it owns) or a Point (which it maintains a reference to.)
So the problem becomes "how do we correctly implement a <<Union>>", which may have a fairly straightforward answer. Why not have two methods, either one of which may return null (but one must return a value):
+ public DirectPosition getDirect() ;
+ public Point getIndirect() ;
This would seem to be consistent with the UML in Figure 14 of OGC Topic 1 and the text in Clause 6.4.5.
Neither Point nor DirectPosition should extend Position unless this is how we intend to implement <<Unions>>. Implementing <<Union>> with a type heirarchy seems confusing to me because it produces parent-child relationships where none should exist.
Looking at this code again, I think it would be very hard to use this interface! "Cast the object if it is a Point or call getPosition() if the object is a DirectPosition?" You're just iterating over a collection of Positions for the most part. You're not supposed to write code which assumes that the Position is one representation or the other. If we remove the inheritance and put in the two methods above, we have an even handed way of checking which representation is present.