(under)
(right)
(over)
(type)
(signature)
(classes)
set_age : Person * Integer -> Voidthat is defined as set_age(p,n) { p.age = n; }. Now consider the following fragment of code:
Person* p = r;where we employ object reference notation when calling . Since we have assigned r (which is referring to a Retiree) to p, we know that p now points to a Retiree, and since a Retiree is a person we may apply the function . However, sets the age of the Retiree to 40, which gives (by common standards) a semantic error. The lesson that we may draw from this is that being a subset is no guarantee for being a subtype as defined by the principle of substitutability. However, we may characterize the relation between a Retiree and a Person as being of a weaker kind, namely read-only substitutability, expressing that the (value of) the subtype may be used safely everywhere an instance of the supertype is expected, as long as it is not modified. Read-only substitutability holds for a type that stands in a subset relation to another type or is embeddable (as a subset) into that type. See slide 8-subst.r refers to some Retiree
p->set_age(40);
procedure search(name, module) if name = action then do action elsif inherited = nil then undefined else search(name, inherited)