> -- Valery Solovey писал(а):
> Можно по-подробнее?## Код:
```
TYPE
Object = POINTER TO ObjectDesc;
Method = PROCEDURE (obj: Object);
ObjectDesc* = RECORD
   do*: Method; (* overridable (="virtual") method *)
END;

NewObject = POINTER TO NewObjectDesc; (* this object can be in a different module *)
NewObjectDesc* = RECORD (ObjectDesc)
   inheritedDo: Method; (* a saved copy of ObjectDesc.do *)
END;

PROCEDURE DefaultMethod (obj: Object); (* can't be called directly if not exported from the base module *)
BEGIN
   (* do something *)
END DefaultMethod;

PROCEDURE Init* (obj: Object); (* initialize a new Object instance *)
BEGIN
   obj.do := DefaultMethod; (* assign the default method implementation *)
END Init;

(* the following procedures can be in a different module along with the NewObject itself *)

PROCEDURE NewMethod (obj: Object);
BEGIN
   obj(NewObject).inheritedDo(obj); (* <- call the inherited method *)
   (* do something else *)
END NewMethod;

PROCEDURE InitNewObject* (obj: NewObject);
BEGIN
   Init (obj); (* here obj.do will be initialized to the unpublished DefaultMethod *)
   obj.inheritedDo := obj.do; (* <- remember the inherited method *)
   obj.do := NewMethod; (* <- set our new method handler *)
END InitNewObject;
```
Для сравнения - аналогичный код на КП:## Код:
```
TYPE
Object* = POINTER TO EXTENSIBLE RECORD
END;

NewObject = POINTER TO RECORD (Object)
END;

PROCEDURE (obj: Object) Do* (), NEW;
BEGIN
   (* do something *)
END Do;

PROCEDURE (obj: NewObject) Do ();
BEGIN
   obj.Do^(); (* <- call the inherited method *)
   (* do something else *)
END Do;
```
Ни явных инициализаций, ни запоминания прежнего метода при наследовании. Автоматическое созданиеVMTсупротив ручного.