Casting Operators

There is a single casting operator available for use in an assignment operation. The basic syntax is:

<object> := <anObject> AsA <class>

The AsA operator allows safe downcasting of an object to a more specific sub-class in the same inheritance hierarchy provided that the following rules are not violated when the expression is validated:

At runtime the assignment/cast fails if <anObject> does not contain an instance of the class of which <object> is an instance. In that case Glb.Status is set to "*****" and <object> is unchanged.

If the assignment/cast is successful a deep copy is performed from <anObject> to <object> to preserve all of the attribute data.

Example

Consider the situation where ClassA is a superclass, ClassB and ClassD directly inherits from ClassA, and ClassC inherits from ClassB.

In this case, the following are valid uses of AsA assuming that all classes are also instances (Multiplicity = 1):

The following are invalid uses: