Consultation (object-oriented programming)
Encyclopedia
Consultation in object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 occurs when an object's method implementation consists of a message send of the same message to another constituent object.

Example

class CustomerList
{
List customers = new ArrayList;
public void add(Customer customer)
{
customers.add(customer); // this is a consultation
}
}

In this example, the add method of CustomerList consults the List instance to implement the semantics of adding a value to the list. Consultation can be very useful if extra conditions or side-effects have to occur on the method invocations. For instance in this example, the add method can be used to check if the customer is not yet in the list, and to check for non-null customer object.

Delegation

Consultation is often incorrectly referred to as delegation
Delegation (programming)
In object-oriented programming, there are two related notions of delegation.* Most commonly, it refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls as defined by Lieberman in his 1986 paper "Using Prototypical Objects to Implement...

. The main differences with delegation are that consultation is explicit in the code not a language mechanism as such, and that consultation does not preserve late binding of self whereas delegation does.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK