Late Binding
In most object-oriented languages, calls to methods are represented physically by a pointer to the code in memory. This restricts the design of an application since specific "command handling" classes are required, usually organized according to the chain-of-responsibility design pattern. While Cocoa retains this approach for the most part, Objective-C's late binding opens up more flexibility.
Under Objective-C, methods are represented by a selector, a string describing the method to be called. When a message is sent, the selector is sent into the ObjC runtime, matched against a list of available methods, and the method's implementation is called. Since the selector is text data, this allows it to be saved to a file, transmitted over a network or between processes, or manipulated in other ways. The implementation of the method is looked up at runtime, not compile time. There is a small performance penalty for this, but late binding allows the same selector to reference different implementations.
By a similar token, Cocoa provides a pervasive data manipulation method called key-value coding (KVC). This permits a piece of data or property of an object to be looked up or changed at runtime by name — the property name acts as a key to the value itself. In traditional languages, this late binding is not possible. KVC leads to great design flexibility — an object's type does not need to be known, yet any property of that object can be discovered using KVC. In addition, by extending this system using something Cocoa calls key-value observing (KVO), automatic support for Undo/Redo is provided.
Late static binding is a variant of binding somewhere between static and dynamic binding. The binding of names before the program is run is called static ("early"); bindings performed as the program runs are dynamic ("late" or "virtual").
Read more about this topic: Cocoa (API)
Famous quotes containing the words late and/or binding:
“I was brought up in the great tradition of the late nineteenth century: that a writer never complains, never explains and never disdains.”
—James A. Michener (b. 1907)
“[Governments] true strength consists in leaving individuals and states as much as possible to themselvesin making itself felt, not in its power, but in its beneficence, not in its control, but in its protection, not in binding the states more closely to the center, but leaving each to move unobstructed in its proper orbit.”
—Andrew Jackson (17671845)