Originale-mail to me for new edition

 

Changing inherited implementations

 

Descendant classes can change the way a specific interface method is implemented by overriding the implementing method. This requires that the implementing method be virtual or dynamic.

A class can also reimplement an entire interface that it inherits from an ancestor class. This involves relisting the interface in the descendant class’s declaration. For example,

type

  IWindow = interface

    ['{00000115-0000-0000-C000-000000000146}']

    procedure Draw;

    ...

  end;

  TWindow = class(TInterfacedObject, IWindow)  // TWindow implements IWindow

    procedure Draw;

    ...

  end;

  TFrameWindow = class(TWindow, IWindow)  // TFrameWindow reimplements IWindow

    procedure Draw;

    ...

  end;

Reimplementing an interface hides the inherited implementation of the same interface. Hence method resolution clauses in an ancestor class have no effect on the reimplemented interface.

 

Topic groups

 

See also

Implemeting interfaces

Method resolution clause

 

 

译文

 

改变继承得到的实现

 

后裔类可以通过覆盖实现的方法来改变指定的接口方法。这要求实现方法是虚拟的(virtual)或动态的(dynamic)。

一个类还可以再实现一个完整的接口,该接口从一个祖先类中继承而来。这涉及到在后裔类的声明中再次列出接口。例如,

type

  IWindow = interface

    ['{00000115-0000-0000-C000-000000000146}']

    procedure Draw;

    ...

  end;

  TWindow = class(TInterfacedObject, IWindow)  //TWindow实现IWindow

    procedure Draw;

    ...

  end;

  TFrameWindow = class(TWindow, IWindow)  //TFrameWindow再实现IWindow

    procedure Draw;

    ...

  end;

再实现接口将隐藏继承得到的同一接口的实现。因此祖先类中的方法决定子句不影响再实现接口。

 

主题组

 

相关主题

实现接口

方法决定子句