C.4 Delegation

XPCE does not offer multiple inheritance. Sharing functionality from multiple classes is generally dealt with using delegation. Delegation implies that messages not understood by a principal object are forwarded to an object that is associated to it.

For example, XPCE defines class editor to be a graphical object capable of editing text. Most applications require a window capable of editing text. This is implemented by XPCE's class view, which is not a subclass of both editor and window, but just of window. The window displays an instance of class editor and constrains the size of the editor to occupy the entire visible area of the window. Any message arriving on the view that is not defined on class view (or class window) will be forwarded to the associated editor object.

The dynamic nature of delegation makes this mechanism more flexible than multiple inheritance. For example, XPCE defines class node. This class defines the communication to a tree to automate the layout of hierarchies. A node can manipulate any graphical object. Using multiple inheritance would require a class box_node, circle_node, etc.