[Uml-devel] ambiguity
Andrew Sutton
ansutton at kent.edu
Wed Jan 15 10:46:03 UTC 2003
On Wednesday 15 January 2003 1:14 pm, Andrew Sutton wrote:
> hey, does anybody know anything about disambiguating the "OO circle of
> death" inheritance problem? as i go thru the MOF implementation i'm finding
> a couple of instances of multiple inheritance that make the inheritance
> tree cyclic.
okay... i found a solution, but i don't know how well it scales to large
inheritance hierarchies (like MOF and UML): virtual base classes :(
actually, i lied about the previous example. there's another couple layers to
the hierarchy.
> class UObject; // umbrello object, most base class ever
> class RefBaseObject : public UObject;
> class RefFeatured : public RefBaseObject;
> class RefObject : public RefFeatured;
> class ModelElement : public RefObject
> class TypedElement : public ModelElement;
> class DataType : public ModelElement;
> class AliasType : public DataType, public TypedElement;
with a cleverly added VBC:
class UObject; // umbrello object, most base class ever
class RefBaseObject : public UObject;
class RefFeatured : public RefBaseObject;
class RefObject : public RefFeatured;
class ModelElement : virtual public RefObject; <-- note virtual
class TypedElement : public ModelElement;
class DataType : public ModelElement;
class AliasType : public DataType, public TypedElement;
this is supposed to ensure that duplicate instances of the RefObject class do
not exist in instances of derived types. so, in theory, returning a reference
to a RefObject for an instance of AliasType will not result in an ambiguous
base class error.
so far so good, right? maybe. all the classes with the exception of AliasType
are abstract and *might* appear in other circular inheritance hierarchies.
the problem is easy to understand in small doses, but what about generalized
references "mid-hierarchy". in the example given above, there are multiple
instances of ModelElement in the AliasType class. if we wanted to return a
reference to ModelElement for an AliasType, we'd probably get an ambiguous
base class error. one solution might be to always virtually derive abstract
base classes, but i don't know if that would work. i haven't seen any
examples where the most derived class virtually derives its multiple bases.
furthermore, there seems to be some caveat the the most derived class must
call the constructors for virtually derived classes. if the entire
inheritance hierarchy (excepting non-abstract classes) is virtually derived,
then the non-abstract classes would have to construct ever single class in
the inheritance hierarchy.
another good question is whether or not we find multiple instances of
non-virtually derived Ref classes in instantiated objects. all the
documentation that i've found indicates that the multiple instances of the
virtual base class are "unified" (as opposed to distinct). if that's the
case, are the base classes of the VBC also unified?
man, i thought i had C++ down pat. maybe i'm not as good of a programmer as i
thought ;)
andy
More information about the umbrello-devel
mailing list