Interface definition prerequisites
To specify that an interface requires the presence of other interfaces
when implemented, GObject introduces the concept of
prerequisites: it is possible to associate
a list of prerequisite types to an interface. For example, if
object A wishes to implement interface I1, and if interface I1 has a
prerequisite on interface I2, A has to implement both I1 and I2.
The mechanism described above is, in practice, very similar to
Java's interface I1 extends interface I2. The example below shows
the GObject equivalent:
In the G_DEFINE_INTERFACE
call above, the third parameter defines the prerequisite type. This
is the GType of either an interface or a class. In this case
the ViewerEditable interface is a prerequisite of
ViewerEditableLossy. The code
below shows how an implementation can implement both interfaces and
register their implementations:
It is very important to notice that the order in which interface
implementations are added to the main object is not random:
g_type_add_interface_static,
which is called by
G_IMPLEMENT_INTERFACE,
must be invoked first on the interfaces which have no prerequisites and then on
the others.