Safety (Cont.)
Redefined Attributes and Methods (Cont.)
(Redefinition of attributes)
The type of a redefined attribute must be a subtype of the type of the original attribute.
Assume
a is a variable of type
classA.
If
a references an object of class
classB:
- If
classC is a superclass of classD, redefinition can not lead to a type violation.
- If
classD is a superclass of classC, the expression a.attr.attr' will lead to a type violation as soon as attr' is an attribute which is defined only for classC.
(Redefinition of methods)
The types of the arguments of the redefining signature must be supertypes of the arguments of the redefined signature.
classB IsA classA
meth ( classA, type11, ..., type1k ): typeA
meth ( classB, type21, ..., type2l ): typeB
|
Assume
a is a variable of type
classA.
If
a references an object belonging to
classB:
k must be equal to l.
- From the same arguments above,
typeB must be a subtype of typeA.
- Since variable
a is of type classA, one can at best guarantee the restrictions of the types of the arguments of the signature attached to classA.
How to avoid stress at work.
1. Don’t go to work.
|