gnome-class
gnome-class copied to clipboard
Class virtual fields, virtual/non-virtual class methods
GObject has two "weird" features that you don't find in many OO systems.
- You can have class fields that are "virtual". These would be inside the class struct, but each subclass has its own version of it and can override its value during class initialization, inside the base_class_init function. A subclass inherits the value from the parent class, but gets its own copy.
This is different from e.g. static fields in Java or C++, which are exactly the same for each subclass.
This is used in GStreamer, and "internally" also in GObject itself (you add properties to the class, but each subclass can override them).
- Class methods and virtual class methods, that take the class struct as argument. See g_object_class_find_property() and various gst_whatever_class_do_something() functions in GStreamer. Or gtk_widget_class_set_template_from_resource() in GTK.
It would be nice to support these (or at least be able to hook into class_init / base_class_init).