GObject
GObject
|
|
---|---|
Sample GObject code: Adding the property file-size to a class.
|
|
Basic data
|
|
developer | The GTK + team |
Publishing year | 2002 |
Current version | 2.60.1 (April 15, 2019) |
operating system | Unix , Windows , OS / 2 , BeOS |
programming language | C. |
category | Program library |
License | LGPL |
German speaking | No |
www.gtk.org |
GObject is a program library published under the free LGPL license and a framework that enables object-oriented programming in the C programming language and can be used on many platforms.
description
GObject's approach corresponds to that of Objective-C , which is used for application development under macOS (see Cocoa ) . GObject is the foundation of all GTK + / Gnome applications and the base class of all GTK / Gnome classes . GObject only depends on the libc (see Standard C Library / glibc ) and the GLib . GObject provides further functionalities such as events , boxing of data types , error handling and reference counting . Object types are only registered at runtime . This enables good introspection of the classes, but at the expense of strong type security .
In contrast to C ++, the object orientation with GObject does not allow multiple inheritance . Instead, interfaces such as Java or C # are used. A class in GObject is implemented by at least two C structures : One of them contains the information of the class, for example the methods / VTable and static member variables . The second contains the member variables as instance information, for example. There are no public, protected, or private access modifiers as in the programming languages C ++, Java, or C #; private class members can, however, be implemented using additional hidden C structures. These private structures are not defined in the class public header files . When creating a GObject class, many macros and initialization functions have to be written manually. The tool GOB2 (GObject Builder), which offers a syntax borrowed from Java, is available to make writing classes easier . GOB2 acts as a preprocessor , which generates code for the C compiler from the object templates. An alternative to GOB2 is the Vala / Genie programming language , which, in addition to the code structure, is also able to translate the entire source text from a C # -like language.
Important restrictions of the GObjekt framework are the lack of support for namespaces , no possibility of overloading operators and methods as well as the purely "manual" exception handling .
history
Originally, GTK's object system was closely interwoven with GTK's user interface. It was not until version 2.0 of GTK / Gnome was it moved into its own framework so that this object system can also be used without the integration of GTK for, for example, pure command line-controlled applications and server applications without a graphical user interface .
commitment
The combination of C and GObject is used in many successful open source projects, above all GTK + and ultimately the complete Gnome desktop as well as GIMP , Pango and many others.
literature
- The GTK + / GNOME Developer Handbook , Matthias Warkus 2008, dpunkt verlag - Well-founded introduction to GObject implementation in chapter three
Web links
- GObject API documentation (English)
- GOB2 - GObject Builder (English)
- Vala Project - GObject preprocessor and programming language (English)