Chaining up is often loosely defined by the following set of
conditions:
Parent class A defines a public virtual method named foo and
provides a default implementation.
Child class B re-implements method foo.
B’s implementation of foo calls (‘chains up to’) its parent class A’s implementation of foo.
There are various uses of this idiom:
You need to extend the behaviour of a class without modifying its code. You create
a subclass to inherit its implementation, re-implement a public virtual method to modify the behaviour
and chain up to ensure that the previous behaviour is not really modified, just extended.
You need to implement the
Chain
Of Responsibility pattern: each object of the inheritance
tree chains up to its parent (typically, at the beginning or the end of the method) to ensure that
each handler is run in turn.
To explicitly chain up to the implementation of the virtual method in the parent class,
you first need a handle to the original parent class structure. This pointer can then be used to
access the original virtual function pointer and invoke it directly.
Use the parent_class pointer created and initialized
by the
G_DEFINE_TYPE
family of macros, for instance: