Re: GObject: Class and Instance Method



Hi Matthias,

On Sat 31 Jul 2010 06:05, Matthias Berndt <berndt matthias gmx de> writes:

>> If you put them in the object struct, every time you instantiated a Foo object
>> you'd have to fill in the bar function pointer to point to the same
>> implementation; by putting them in the class struct, this becomes unnecessary.
>
> My question was more about "How is it correct for GObject?" and less
> about "How ist it efficent?". I'm sorry if I wasn't able to place a
> clear question.

Sometimes you want to use types to express behavior -- that's what
vmethods in GObjectClass are for. Sometimes you want instances to behave
differently, even if they are under the same type, like for GstPad in
GStreamer. That's what ad-hoc vmethods in instances are for.

You might appreciate the analogy between class-based inheritance, like
in Java, and prototype-based inheritance, like in Self (or
Javascript). GObject's native support is more for class-based
inheritance (vmethods in GObjectClass), but it lets you build other
things too.

This discussion might be better continued on gtk-app-devel-list, FWIW.

Andy
-- 
http://wingolog.org/


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