GObject is a library and framework which provides Object-oriented programming for the C programming language. It is released under the liberal LGPL license for many platforms.
Its approach is compareable to that of Objective-C which is used in application development for Mac OS X (see Cocoa). Being the fundament of all GTK/GNOME applications, GObject is the base class of all GTK/GNOME classes. This library depends only on libc and Glib.
GObject also provides additional features like events, boxing of datatypes, error handling and refcounting. Object type information is registered at runtime therefore offering good support for introspection .
Unlike C++, object orientation with GObject does not allow multiple inheritance. Instead it uses interface classes compareable to Java or C# interfaces. A class in GObject is implemented by at least two C structs: One that holds the information for the class e.g. methods/vtable and another that contains the instance information e.g. member variables. There are no access modifiers "public, protected, private" like in C++, C# or Java but private members can be implemented by adding an additional, hidden struct which is not defined in the C public header files of that class. Lots of manual definitions of macros and initializers are necessary to create a new class. An optional tool called GOB2 eases this process of writing objects for GObject by offering a Java like syntax. GOB2 acts as a preprocessor to the C compiler generating code from object templates.
Important drawbacks of the GObject framework are the absence of operator overloading, exceptions and namespaces. Despite some missing features GObject is easier to learn and get started with than object orientation in C++.
History
Before Gtk version 2.0 the object system was dependent on the Gtk userinterface libraries. It was decoupled and placed in it's own independent framework to enable commandline applications and server applications without using the Gtk GUI library.
Uses
The combination of C and GObject is well accepted and used in many successful Open source projects including the GNOME desktop, GIMP and many others.
Weblinks