Delegation (software development)

from Wikipedia, the free encyclopedia

Delegation (from English delegation , delegation ',' transfer ') has different meanings in object-oriented programming , all of which have to do with dynamic method binding at program runtime:

  • an object-oriented variant of method pointers, especially in .NET languages ​​such as C # .
  • object-based inheritance (as opposed to the usual class-based inheritance ). Here, an object (automatically) takes over properties and functionalities that it does not explicitly define itself from another concrete object, its prototype.
  • Originally the implementation of methods of an object equivalent by calling methods of another object, even English consultation (for consultation, advice) or invocation called (call). This variant fits the proxy and adapter design patterns .
  • The languages Swift and Objective-C developed by Apple know the keyword delegate as a functionality specialization : Here an object can be queried for any functionality (method) at runtime. This is then possibly carried out in the context of the questioning object, as if it were part of the questioning object.

background

In the area of object-oriented programming , inheritance or common types of relationships such as interaction or aggregation can not guarantee a satisfactory separation of service provider and service user in some cases . All of the above concepts require a binding prior to the runtime. If the service provider is changed, users may no longer be able to use it because they no longer understand its interfaces. In such cases, the delegation provides a constant interface for the user and delegates the calls to a layer below. In computer science, this has been used for a long time in research on artificial intelligence .

As a design sample

In the design patterns of the Gang of Four (Engl. For Gang of Four ) instead of the general delegate of is proxy or the adapter spoken. In general, the user of a service only knows the interface to a representative of the service provider and the protocol, i. H. how to use the interface. The representative hides the service provision behind more or less dynamic procedures to identify a specific service provider. The transferred data can be processed. In addition, the representative can identify error and exceptional situations and even offer appropriate measures such as the selection of alternatives for the delegation.

As a language element

The simple definition of delegation is that the function calls have the same behavior as virtual function calls ; the most specified function is always called. Respectively, it is the original function, which represents the beginning of the so-called lookup (English for "lookup"), even if it has transferred control to another object. Delegation has the advantage that it can take place at runtime. It can also be reversed during the runtime. Inheritance could also group function calls in such a way, target the type of an entity and is limited to compilation time. The disadvantage of delegation is that it cannot be considered completely type-safe (G. Kniesel showed, however, that a restricted version can be type-safe). Delegation can also be referred to as “runtime inheritance for specific objects”.

Programming languages ​​normally do not support the concept of delegation, but there are a few exceptions: ECMAScript , Self , G. Kniesels Lava, and the Tcl object system Snit . Lava uses an explicit delegation link, which can never be null and never changes during the lifetime of an object. Self has the language element of the explicit parent slots , which can change during runtime. Since there are many parent slots , Self basically has the ability to inherit multiple times. The delegation in Self is realized by the language element mutable parent slots . This concept is explained in a number of works in the literature on object-oriented system development, but it should be noted that there is no standardized terminology. As with the dual inheritance described below, a carefully designed function lookup scheme is required.

Dual inheritance

If the programming language supports delegation and inheritance, dual inheritance can be used by using both mechanisms at the same time:

 class C extends A
 {
     delegationlink D d
 }

In this example additional rules regarding the lookup of the functions are necessary, since two functions can be described as potentially the most specified. This is elaborated in K. Graversen's doctoral thesis regarding rules.

Related areas

Delegation can be described as a low-level mechanism used to exchange code between two entities. Object-oriented programming languages ​​in particular use delegation. Older programming languages ​​in particular claim to be proficient in delegation, although they actually implement the aggregation, which is related to the different definitions of delegation.

Research on distributed delegation has recently been carried out in the area of ​​search engines. Search engine clients use a distributed entity that provides the best search results as well as general, reusable functionality.

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

The delegation is a fundamental programming technique in prototype-based programming languages ​​such as JavaScript .

See also

Web links

Individual evidence

  1. Dirk Louis and Shinja Strasser, Microsoft Visual C # 2008 - The Developer Book , Microsoft Press Germany, 2008, ISBN 978-3-86645-507-8 , chapter Delegates and Events
  2. ^ Henry Lieberman, Using Prototypical Objects to Implement Shared Behavior in Object Oriented Systems , in: OOPSLA, 1986, pp. 214-223
  3. Günter Kniesel, Type-Safe Delegation for Run-Time Component Adaption ( Memento of the original from December 12, 2013 in the Internet Archive ) Info: The archive link was automatically inserted and not yet checked. Please check the original and archive link according to the instructions and then remove this notice. (PDF; 72 kB), ECOOP '99 Proceedings of the 13th European Conference on Object-Oriented Programming, Springer-Verlag London, 1999, table of contents ISBN 3-540-66156-5 @1@ 2Template: Webachiv / IABot / www.st.informatik.tu-darmstadt.de
  4. For the definition of terms see Darwin Project - What is (Not) Delegation ( Memento of February 13, 2013 in the Internet Archive ), Uni Bonn (English)
  5. Ulrich Frank and Sören Halter, " Delegation: A useful addition to current object-oriented modeling concepts (PDF; 147 kB)", information system architecture. Circular letter of the GI technical committee 5.2, 3rd year, issue 1, Sept. 1996, pp. 16-19
  6. Lava ( Memento of the original from May 29, 2009 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. , University of Bonn  @1@ 2Template: Webachiv / IABot / www.informatik.uni-bonn.de
  7. KB Graversen, and K. Østerbye, “Implementation of a Role Language for Object-Specific Dynamic Separation of Concerns” ( Memento of the original from November 21, 2008 in the Internet Archive ) Info: The archive link was automatically inserted and not yet checked. Please check the original and archive link according to the instructions and then remove this notice. (PDF; 405 kB), AOSD Workshop SPLAT: Software engineering Properties of Languages ​​for Aspect Technologies, March 2003 @1@ 2Template: Webachiv / IABot / aosd.net