Re: glib interfaces

Miroslaw Dobrzanski-Neumann wrote:

Hi all
I have just two questions

According to Tim, interfaces in glib are closer to gcc signatures (see the info pages) than java style interfaces.

1. Why it is not possible to derive from interfaces? My intention was to
  extend an interface by deriving a new one from the other.

Deriving interfaces doesn't really fit into glib's interface model. You can instead define a new interface that provides the aditional functionality. You can add the "parent" interface as a prerequisite to the new interface in order to ensure that types that implement your new interface also implement the parent one.

2. What is purpose of g_type_interface_add_prerequisite()? How it behaves?
  What constraints does it place on given interface?

add_prerequisite() adds a prerequisite for implementing a type. It says that if a type wishes to implement an interface I, then it must be a T (for some type T).

For instance, you might require that all types implementing your interface be subclasses of GObject (it is possible for instantiable types other than GObjects to implement interfaces, although you will probably never make use of this). Or as above, to simulate derivation of interfaces, you might add a prerequisite that all types implementing the "derived" interface must also implement the "parent" interface.

Adding a prerequisite on GObject is quite useful for an interface, as it lets you use that type id for arguments to a signal (since implementations of an interface need not be GObjects, the signal code wouldn't know how to manage the argument otherwise).

Hope this helps.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]