mac_ch9.eps
co_bar.eps

Chapter 9: Using Cocoa Design Patterns and Advanced Messaging

mac_chbox9.eps

In This Chapter

Understanding Model-View-Controller in Cocoa

Understanding and using target-action

Using Key-Value Coding

Using Key-Value Observing

Working with notifications and errors

It's traditional in a Cocoa book to mention design patterns and features such as Model-View-Controller (MVC), target-action, Key-Value Coding (KVC), and Key-Value Observing (KVO).

Apple's documentation mystifies these design patterns and makes them seem more difficult and complex than they really are. They're an essential part of Cocoa, and you can use them to implement impressively efficient code. But the practice can be much simpler than the theory.

Understanding Model-View-Controller

Model-View-Controller, often shortened to MVC, was introduced in Chapter 2. The outline of MVC is shown in Figure 9.1. An application is split into three elements — a store of data called a model, an interface called a view, and a controller object that passes data between them.

MVC implies, but doesn't enforce, the suggestion that model data should be kept in separate objects and perhaps in separate custom classes.

In a simple application, this seems ...

Get Cocoa® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.