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:

    While nature thus very early and very abundantly feeds us, she is very late in tutoring us as to the proper methodization of our diet.
    Herman Melville (1819–1891)

    What is lawful is not binding only on some and not binding on others. Lawfulness extends everywhere, through the wide-ruling air and the boundless light of the sky.
    Empedocles 484–424 B.C., Greek philosopher. The Presocratics, p. 142, ed. Philip Wheelwright, The Bobbs-Merrill Co., Inc. (1960)