Delegation (programming) - Design Pattern

Design Pattern

Delegation is the simple yet powerful concept of handing a task over to another part of the program. In object-oriented programming it is used to describe the situation where one object defers a task to another object, known as the delegate. This mechanism is sometimes referred to as aggregation, consultation or forwarding (when a wrapper object doesn't pass itself to the wrapped object).

Delegation is dependent upon dynamic binding, as it requires that a given method call can invoke different segments of code at runtime. It is used throughout Mac OS X (and its predecessor NeXTStep) as a means of customizing the behavior of program components. It enables implementations such as making use of a single OS-provided class to manage windows because the class takes a delegate that is program-specific and can override default behavior as needed. For instance, when the user clicks the close box, the window manager sends the delegate a windowShouldClose: call, and the delegate can delay the closing of the window if there is unsaved data represented by the window's contents.

It has been argued that delegation may in some cases be preferred for inheritance to make program code more readable and understandable.

Read more about this topic:  Delegation (programming)

Famous quotes containing the words design and/or pattern:

    With wonderful art he grinds into paint for his picture all his moods and experiences, so that all his forces may be brought to the encounter. Apparently writing without a particular design or responsibility, setting down his soliloquies from time to time, taking advantage of all his humors, when at length the hour comes to declare himself, he puts down in plain English, without quotation marks, what he, Thomas Carlyle, is ready to defend in the face of the world.
    Henry David Thoreau (1817–1862)

    Man is eminently a storyteller. His search for a purpose, a cause, an ideal, a mission and the like is largely a search for a plot and a pattern in the development of his life story—a story that is basically without meaning or pattern.
    Eric Hoffer (1902–1983)