Bruce said:
No. Static members do not participate in inheritance and therefore do
not participate in polymorphism.
This has bothered me for a while. I wonder why Anders left this feature
out of C# - Delphi supports virtual class methods (i.e. virtual static
methods), as well as virtual constructors, which you can call through
metaclass types. You can get the same effect by using nested
interfaces, factory classes, etc., but virtual class methods are much
cleaner.
OTOH, even in Delphi, you can't put class methods in an interface.
You'd have to use a base class, something like this:
type
TBase = class
public
class procedure MyMethod; virtual; abstract;
end;
TDerived1 = class(TBase)
public
class procedure MyMethod; override;
end;
TDerived2 = class(TBase)
public
class procedure MyMethod; override;
end;
// now to use MyMethod polymorphically...
procedure CallMyMethod;
var
whichClass: class of TBase;
begin
if SomeCondition then
whichClass := TDerived1
else
whichClass := TDerived2;
whichClass.MyMethod;
end;
Jesse