Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cocoa (API)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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 needed, usually organized according to the [[chain-of-responsibility pattern]]. While Cocoa retains this approach for the most part, Objective-C's [[Name binding#Late static|late binding]] opens up more flexibility. Under Objective-C, methods are represented by a ''selector'', a string describing the method to call. When a message is sent, the selector is sent into the Objective-C runtime, matched against a list of available methods, and the method's ''implementation'' is called. Since the selector is text data, this lets it 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,<ref>[[Wikibooks:Programming Mac OS X with Cocoa for beginners/Objective C, the language and its advantages#Some Objective-C advantages|Wikibooks - Some Objective-C advantages]]</ref> 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).<ref>{{Cite web |url=https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/ |title=Key-Value Coding Programming Guide |access-date=September 27, 2021}}</ref> This allows 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. In traditional languages, this late binding is impossible. KVC leads to great design flexibility. An object's type need not be known, yet any property of that object can be discovered using KVC. Also, by extending this system using something Cocoa terms ''key-value observing'' (KVO), automatic support for [[undo|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'').
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)