O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AppKit Design Patterns

Besides 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.

Model-View-Controller

The Model-View-Controller (MVC) pattern is the driving design pattern in the Application Kit.[3] The premise of this pattern is that code may be split up into logically distinct units that each perform a specific role:

  • The model is an object that encapsulates data and provides logic that manipulates that data.

  • The view is a separate object that only knows how to display data.

  • The controller is an arbiter between the model and the view. The controller’s job is to take data from the model and pass it to the view where it can be displayed. If the view is interactive—able to accept user input—then the controller will interpret those actions and instruct the data model to do something in response.

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.

MVC used to display two different views of the same data
Figure 3-1. MVC used to display two different views of the same data

Target/Action

The Application Kit uses ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required