Polymorphism/Access to the super class method definition
Like any
other object language, the sending of a message supports polymorphism. We are going to use the previous example to distinguish attributes from
other features ("format" example).
Class:printFeature()
{
PartFeature.<print();
}
Feature:print()
{
// The current object is a Feature
StdOut.write("Feature : ", format(), NL);
}
String Feature:format()
{
return Name; // Very simple formatting...
}
String Attribute:format()
{
// The formatting consists in prefixing
// the name of '(Attribute) '
return "(Attribute) " + super.format;
}
The "super"
pseudo-variable, used in the "format"
method of Attribute, is used to send a message to the current
object (here it is "format") defined in its parent class. This characteristic authorizes code
factorization in the parent classes.