IInterface and Inheritance An interface, like a class, inherits all of its ancestors' methods. But interfaces, unlike classes, do not implement
methods. What an interface inherits is the obligation to implement methods an obligation that is passed onto any
class supporting the interface.
The declaration of an interface can specify an ancestor interface. If no ancestor is specified, the interface is a direct
descendant of
IInterface
, which is defined in the
System
unit and is the ultimate ancestor of all other interfaces.
On Win32,
IInterface
declares three methods:
QueryInterface
,
_AddRef
, and
_Release
. These methods
are not present on the .NET platform, and you do not need to implement them.
Note: IInterface
is equivalent to
IUnknown
. You should generally use
IInterface
for platform independent
applications and reserve the use of
IUnknown
for specific programs that include Win32 dependencies.
QueryInterface
provides the means to obtain a reference to the different interfaces that an object supports.
_AddRef
and
_Release
provide lifetime memory management for interface references. The easiest way to
implement these methods is to derive the implementing class from the
System
unit's TInterfacedObject. It is also
possible to dispense with any of these methods by implementing it as an empty function; COM objects, however,
must be managed through
_AddRef
and
_Release
.