Re: GObject: Class and Instance Method



On Fri, 30 Jul 2010 at 09:45:14 +0200, Matthias Berndt wrote:
> I understand it as the instance method for an object instance is
> declared on the class. Declaring the method on the instance data
> structure seems more logical to me. I mean something like this:

Instance methods (as they're normally understood, e.g. as seen in C++ or Java)
are defined as part of the class, because each instance of the same class has
the same implementation of each method.

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.

The fact that there's a class struct and a separate object struct is an
artefact of the way GObject implements object-orientation in C; other OO
runtimes written in C, like (the C implementation of) Python, work very
similarly. The same sort of thing happens behind the scenes in C++, but you
don't see it in the source code because the compiler takes care of it.

    Simon


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