[ Team LiB ] |
![]() ![]() |
3.1 AppKit Design PatternsBesides leveraging the design patterns and methodologies used with the Foundation framework, the Application Kit relies heavily on several others. Two that merit special attention are Model-View-Controller and Target/Action. 3.1.1 Model-View-ControllerThe Model-View-Controller (MVC) pattern is the driving design pattern in the Application Kit.[1] The premise of this pattern is that code may be split up into logically distinct units that each perform a specific role:
Many views in the MVC pattern may subscribe to the controller, giving the application flexibility to display data in different contexts and formats without heavy modification of the modeling and control logic. This idea is illustrated in Figure 3-1, which shows two views of the same data: a table view of the data and a chart view. Figure 3-1. MVC used to display two different views of the same data![]() 3.1.2 Target/ActionThe Application Kit uses the target/action pattern to decouple UI widgets (controls�typically subclasses of NSControl) from the code that is executed when the user activates the control. In this pattern, a control keeps a reference to a target object that receives an action message. The action message is stored as a selector in an instance variable of the control object. When the user activates the control, the action message is sent to the target. Action messages and targets are generally established in Interface Builder; however, you can change a control's behavior by using the setAction: and setTarget: methods of NSControl. The current target and action of a control may be ascertained programmatically by using the methods target and action. |
[ Team LiB ] |
![]() ![]() |