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:
“When any man expresses doubt to me as to the use that I or any other woman might make of the ballot if we had it, my answer is, What is that to you? If you have for years defrauded me of my rightful inheritance, and then, as a stroke of policy, of from late conviction, concluded to restore to me my own domain, must I ask you whether I may make of it a garden of flowers, or a field of wheat, or a pasture for kine?”
—Matilda Joslyn Gage (18261898)
“With a binding like youve got, people are gonna want to know whats in the book.”
—Alan Jay Lerner (19181986)