A variable
x declared as
var
x : Store;
can refer to objects whose classes have at least
the method signatures of Store. That is, if Store has
methods
proc set(integer)
proc get() : integer
then the assignment
x = MyStore.new();
will be legal if MyStore
has at least methods get and set with the signature
shown above. It does not matter whether MyStore
inherits from Store or not. The type of a class is the set of its method
signatures. A type S is subtype of T if T is in set S. Assignments
of the kind
T = S
are legal. Note parameter passing is just a kind
of assignment.
Class objects do not have classes but they do have a type. Then if one declare
object Figure
public:
proc get() : integer
...
proc set( pn : integer )
...
// here are declared some methods of class Store
end
it is legal to do
x = Figure;
since the type of Figure
is subtype of the type of x, Store. In particular, Any is a
supertype of any class or class object. Then, a method
proc doIt( a : Any )
can receive as parameter any object, be it an
object with a class or a classless object representing a class (as Figure). Note we added to object Figure some methods found in class Store. These methods are automatically added by the
compiler to all classes but not to the class objects. Other methods are added
to all class objects.
The separation of subtyping from subclassing is old. What is new, and very important, is that