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)
“His talent was as natural as the pattern that was made by the dust on a butterflys wings. At one time he understood it no more than the butterfly did and he did not know when it was brushed or marred. Later he became conscious of his damaged wings and of their construction and he learned to think and could not fly any more because the love of flight was gone and he could only remember when it had been effortless.”
—Ernest Hemingway (18991961)