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:
<object> and <class> must be of the same type (<object> must be an instance of <class>)
<object> must be an instance of a sub-class in the same inheritance hierarchy as <anObject>
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):
ClassB := ClassA AsA ClassB
ClassC := ClassA AsA ClassC
ClassC := ClassB AsA ClassC
ClassD := ClassA AsA ClassD
The following are invalid uses:
ClassB := ClassA AsA ClassC
ClassC := ClassA AsA ClassB
ClassB := ClassD AsA ClassB
ClassB := ClassA AsA ClassD
ClassD := ClassA AsA ClassA