Delegation (programming)

Delegation (of English delegation, deputation, Transmission ') has in the object- oriented programming, different meanings, all of which have to do with dynamic method binding for the duration of the program:

  • In particular. NET languages ​​like C # object-oriented variant of method pointers.
  • Object- based inheritance (as opposed to the usual class-based inheritance). Here, an object inherits (automatic) features and functionality, which itself is not explicitly defined by another concrete object, its prototype.
  • Originally the implementation of methods of an object by calling equivalent methods of another object, also English consultation ( for consultation, advice) or invocation (call) called. This variant matches the design patterns proxy and adapter.
  • The Objective-C language knows the delegate keyword as functionality specialization: Here, an object can at runtime by any functionality (method) are interviewed. This can then be executed in the context of the relevant object as if it were part of the question object.

Background

In the area of ​​object-oriented programming can be guaranteed in some cases, by inheritance or common types of relationships such as the interaction or aggregation no satisfactory separation from service providers and users. All concepts mentioned above require a bond before the maturity. If the service provider is changed, the user can no longer use this in some circumstances because they no longer understand its interfaces. The delegation provides in such cases, a constant for the user interface and delegates the calls to an underlying layer. In computer science, this is used among others in the research on artificial intelligence since a long time.

As design patterns

In the design patterns of the Gang of Four (English for gang of four ) is spoken instead of the general delegate of proxy or the adapter. In general, the user of a service only knows the interface to a representative of the service provision and the protocol, that is how the interface should be used. The representative hides behind the service provision more or less dynamic method for determining a specific provider. The editing of the data passed is possible. In addition, the representatives may have errors and detect emergency situations and even offer appropriate measures such as the selection of alternatives of the delegation.

As a language element

The simple definition of delegation is that the function calls have the identical behavior as a virtual function calls, there will always be the most specified function is called. Respectively, it is the original function, which marks the beginning of the so-called lookups (English for " lookup " ), even if it has transferred control to another object. The delegation has the advantage that it can be performed at runtime. It can be undone at run time. The inheritance could summarize function calls such targets the type of an entity and is limited to the compile time. The disadvantage of delegation is that they can not be fully considered as a type-safe (G. Kniesel showed, however, that a limited version can be type- safe). The delegation may also be referred to as " run-time inheritance for specific objects."

Programming languages ​​typically support the concept of delegation did not, but there are a few exceptions: ECMAScript, Self, G. Kniesels lava, as well as the Tcl object system Snit. Lava uses an explicit delegation link, which may be null and never never changes during the lifetime of an object. Self possesses the language element of the explicit parent slots, which can change at runtime. Since many parent slots are available, Self basically has the ability of multiple inheritance. The delegation in Self is realized by the language element mutable parent slots. This concept is explained in a series of papers in the literature on object-oriented system development, however, note that there is no consistent terminology exists. As with the dual inheritance described below requires a carefully designed function -lookup scheme.

Dual inheritance

If the programming language, the delegation and inheritance support, you can use the dual inheritance by using both mechanisms simultaneously:

Class C extends A   {       delegation link D d   } In this example, additional rules in relation to the lookup of the functions are necessary because two functions can be referred to as a potentially most specified. This is elaborated with respect to K. Graversen 's Promovierungsthese rules.

Related areas

Delegation can be described as low-level mechanism that is used to exchange code between two entities. In particular, role-oriented programming languages ​​use the delegation. Notably, older programming languages ​​specify to control delegation, even though they actually implement the aggregation, which is related to the different definitions of the delegation.

Since recently, the research is done on distributed delegation in the search engines. Clients a search engine using a distributed entity that provides the best search results and general, wiederbenutzbare functionality.

The delegation has been proposed as a solution to the aspect-oriented programming by Ernst and Lorenz in 2003.

226192
de