Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Objective-C’s language level support for selectors and the ability to send any message to any object provide a flexible solution to the problem of integrating user interface objects with application code. For example, using Objective-C’s dynamic message sending facilities eliminates the need for manual event handling systems common in other frameworks. Many user interface frameworks are implemented to post events identified by unique integer tags when user interface objects change state. The objects that receive events are then responsible for decoding them and interpreting any information sent with the events. The need to decode events results in the duplication of code such as switch statements or table lookup in multiple places and quickly becomes a maintenance burden. Objective-C’s built-in messaging system makes manual event processing unnecessary.
The popular Signals and Slots pattern developed by Trolltec for its Qt C++ cross-platform framework replicates some of the Outlets, Targets, and Actions pattern. Programmers must subclass framework user interface classes to add application-specific Signals and Slots. Trolltec provides a tool called the Meta Object Compiler that pre-processes application C++ code to generate code that implements the Signals and Slots. Once the specialized code is generated and compiled into an application, the Signals approximate Cocoa’s actions, and the Slots approximate Cocoa’s targets. Cocoa and Apple’s development tools avoid the need for pre-processing and code generation by using Objective-C’s dynamism including the Perform Selector, Anonymous Object, and Responder Chain design patterns.