A PODS interface can extend another PODS interface, meaning that the interface includes all of the methods of its parent interfaces.
For example, you could define an interface PODSCounterDeluxe
to extend the hypothetical PODSCounter
interface described above:
typedef struct PODSCounterDeluxe PODSCounterDeluxe; typedef struct PODSCounterDeluxeVTable { PODSCounterVTable counter; void (*m_decrement)(PODSCounterDeluxe* c); } PODSCounterDeluxeVTable; struct PODSCounterDeluxe { PODSCounterDeluxeVTable* vtable; }; #define PODSdeluxeDecrement©) \ ((c)->vtable->m_decrement)©)) |
This interface adds a decrement
method to the methods defined by the PODSCounter
interface.
If you have a pointer to an object that implements I
, you can safely cast to a pointer to an object implementing an interface that I
extends. For example:
PODSCounterDeluxe* d; ... PODSCounter* c = (PODSCounter* ) d; |
This cast works because the PODSCounterDeluxe
and PODSCounter
structure both contain just a single element: a vtable
pointer. You could cast PODSCounterDeluxeVTable*
safely to PODSCounterVTable*
because PODSCounterDeluxeVTable
extends PODSCounterVTable
. A cast from the interface pointer type PODSCounterDeluxe*
to PODSCounter*
also works.
Casting in the opposite direction would not be safe. Casting up, to the parent interface, is safe. Casting downward, to the child interface is not.
If interface I
extends interface J
, then J
is a super-interface of I
. You must cast when calling a method defined in a super-interface, to avoid a fatal error or warning (depending on the compiler)
when you compile:
PODSCounterDeluxe* d; ... PODSsetCount((PODSCounter* ) d, 0); PODSincrement((PODSCounter* ) d); PODSdeluxeDecrement(d); |
The PODS object model supports single interface inheritance only: an interface can extend only one other interface directly.
This is a simpler model than that provided by the object systems of C++ or Java, both of which allow multiple interface inheritance.
The C interfaces provided by the PODS interface header files generally do not use inheritance beyond inheriting from the base
interface PODSObject
described in the following section. Several manager interfaces (PODSObjectMgr
, PODSDocumentMgr
, PODSEventMgr
) and the PODSButton
interface inherit from PODSObject
indirectly, through an intermediate interface.
PODS interface inheritance illustrates PODS interface inheritance graphically.
The PODSPod
interface is unique in that it also contains data. There is no reason to add methods to a PODSPod
subclass, but you may want to add more data to a PODSPod
subclass.
Send feedback about this page using email. | Copyright © 2008, iAnywhere Solutions, Inc. |