Cocoa (API) - Late Binding

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:

    Books, gentlemen, are a species of men, and introduced to them you circulate in the “very best society” that this world can furnish, without the intolerable infliction of “dressing” to go into it. In your shabbiest coat and cosiest slippers you may socially chat even with the fastidious Earl of Chesterfield, and lounging under a tree enjoy the divinest intimacy with my late lord of Verulam.
    Herman Melville (1819–1891)

    Hate traps us by binding us too tightly to our adversary.
    Milan Kundera (b. 1929)