|
The Darwin Project |
|
What is (Not) Delegation |
|
|
The term delegation originally introduced by Henry Lieberman and implemented in prototype-based languages like Self, is often used in literature to denote another concept, which we prefer to call consultation. The similarities and differences are explained in the folowing and illustrated in figure 1 and figure 2.
|
|
|
Similarities |
In both cases an object, called the child, may have modifiable references to other objects, called its parents. Messages that cannot be executed by the message receiver are automatically forwarded to its parents. When a suitable method is found in a parent object (the method holder) it is executed after binding its implicit self parameter. This parameter refers to the object on whose behalf the method is executed. It is also called this (in Java and C++) and current (in Eiffel). |
|
The Difference |
Automatic
forwarding with binding of self to the message receiver is
called delegation.
Figure 1: Different effect of delegation and consultation on self / this |
|
An Example |
The message empJohn.currentPhone#() produces the result "550055" when the object empJohn delegates to persJohn and "669966" when empJohn consults persJohn. ![]() Figure 2: Different result of the same message for delegation and consultation |
|
Intuition / Mnemonic
|
Intuitively, delegating a message means asking another object to do something on behalf of the message receiver, i.e. as if the message receiver would do it. In contrast, consulting means asking another object how it would do something on its own. |
|
Don´t confuse! |
Unfortunately,
the term delegation is overloaded with many different meanings. For instance,
the "Dictionary of Object Technology" by Firesmith and Eykholt
lists five different definitions of delegation. In particular, delegation
and consultation as defined above should not be confused with
neither of the following:
|
| © 1997-2002 Günter Kniesel |
|