Re: glib interfaces



On Tue, Mar 05, 2002 at 01:05:37PM +0800, James Henstridge wrote:
> 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).
Thanks.

I have tried it with glib 1.3.13 doing the following
(I suppose the gobject code has not changed till now)

register an interface A
ifa = g_type_register_static  (G_TYPE_INTERFACE, "Ifa", ...)

register an interface B
ifb = g_type_register_static  (G_TYPE_INTERFACE, "Ifb", ...)

make ifb dependend on ifa
g_type_interface_add_prerequisite (ifb, ifa):

register a type implementing only ifb
create an object of this type

I've got no error message.

After what you have said the gobject runtime should report an error because
prerequisite ifa was not implemented at all.
Am I right? Is it an error or have I misunderstood the specification?

Regards
-- 
Miroslaw Dobrzanski-Neumann

MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne mosaic-ag com




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