Next: , Previous: Objects, Up: Objects


2.1.2 Delegation

Sheeple supports the runtime sharing of data and behavior. Instead of a fine-grained system where data is shared on a per-property basis, both data and behavior are shared as a whole by establishing parent/child relationships between objects, forming a DAG (directed acyclic graph) data structure of Sheeple objects which determines how and where data and behavior are shared.

Relationships can be established in a number of ways. The OBJECT function may be used, and given a sequence of parents that will be added to the new object as soon as it is created. Using (SETF OBJECT-PARENTS) at any time after object creation will also alter the object's list of parents. Objects created by CLONE automatically inherit the cloned object's list of parents, although that list may subsequently be changed.

A single object can have multiple parents, and multiple children, and Sheeple uses the C3 algorithm to resolve inheritance precedence for data and behavior when multiple inheritance is involved. A readable list of parents belonging to a particular object can be accessed by calling OBJECT-PARENTS. An object's sorted list of ancestors, which determines the order in which objects are queried for data and behavior from most specific to least specific, can be queried with OBJECT-PRECEDENCE-LIST.

Just as relationships can be made, though, relationships can be unmade. (SETF OBJECT-PARENTS) is able to alter, reorder, and otherwise set an existing object's parent list at any time after object creation.

There are some limitations on an object's parent list: First, it is an error for any object except =T= to have an empty parent list. Second, standard objects must all have =STANDARD-OBJECT= and =T= as the last two items in their precedence list, in that order. Finally, the graph generated by a series of connected objects must be acyclic. Failing to fulfill any of these conditions is an error.

A convenient way of inspecting a Sheeple object and its characteristics while working interactively is to use the DESCRIBE lisp function. This will pretty print several useful bits of information about the object, such as its list of parents.