The trait mechanism provides an easy way for two widgets to communicate with each other. Frequently, the two communicating widgets will be a parent and its child; however, unrelated widgets can also communicate through traits. This communication takes two forms:
For example, consider a Motif application that needs to create a menu. To create the menu, the Motif application will need at least one XmRowColumn manager and some appropriate menu children. The XmRowColumn widget needs some way to ask each of its children if they are suitable menu children. The XmQTmenuSavvy trait provides a way. A child widget holding the XmQTmenuSavvy trait is announcing to a menu parent (XmRowColumn) that it is capable of becoming a menu child. Therefore, the menu parent (XmRowColumn) can ask each child if it holds this trait. If a child does not hold this trait, XmRowColumn can issue a warning that the child is not an acceptable menu child.
The XmQTmenuSavvy trait provides several trait methods. One of these trait methods, disableCallback, enables or disables the activate callback method associated with a menu child. Without a trait mechanism, there would be no way for the XmRowColumn widget to call disableCallback. After all, XmRowColumn shares no common ancestry with any primitive widgets. However, since disableCallback is a trait method, XmRowColumn can call disableCallback.