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:
“You can make as good a design out of an American turkey as a Japanese out of his native stork.”
—For the State of Illinois, U.S. public relief program (1935-1943)
“Each child is an adventure into a better lifean opportunity to change the old pattern and make it new.”
—Hubert H. Humphrey (19111978)