2 つのタイプ Max と MinMax を考える。
ObjectType Max is
var n:Integer;
method max(other:Max):Max;
end;
ObjectType MinMax is
var n:Integer;
method max(other:MinMax):MinMax;
method min(other:MinMax):MinMax;
end;
また、以下の 2 つのクラスを考える。
class maxClass is
var n:Integer:=0;
method max(other: Self): Self is
if self then
return self
else return other end;
end;
end;
subclass minMaxClass of maxClass is
method min(other: Self): Self is
if self then
return self
else return other end;
end;
end;
メソッド min と max は binary といわれる。それぞれが
2 つの値( selfと other)について演算するからである。
other は タイプ Self の contravariance ポジション である。
メソッド max は、クラス maxClass から minMaxClass
に継承される。
クラスは のサブクラスであるが、
は のサブタイプにすることはできない。以下のクラスを考える。
subclass minMaxClass' of minMaxClass is
override max(other: Self): Self is if other.min( self)=other then
return self
else return other end;
end;
end;
のインスタンスを とし、 となる。