Excerpt from Beginning IOS Programming by Nick Harris
protocols and Delegates
Model-View-Controller is a great high-level programming pattern,
but to use it in a programming language, you need the tools to
make it work. Objective-C has these tools. The model layer
is implemented using classes and properties to create reusable
objects. The view layer is implemented in the Cocoa and Cocoa
Touch APIs, including reusable views and subviews such as buttons
and text fields. The controller layer is done by using delegates
and data sources to facilitate the communication.
Delegates and data sources are used heavily in Objective-C. It’s
a way of having one part of the software ask for work to be done
by another part. This fits the MVC design pattern with the
communication between views and controllers. Because views interact
only with controllers and never with the model, they need a way of
asking for model data from the controller. This is the role of the
data source. When a user interacts with a view, the view needs to
tell the controller about it. Delegates are used for this role.
Typically, your controller will perform both of these roles.
A view needs to define all the questions it may ask its data source
and what type of answer it expects in return. It also needs to
define all the tasks it may ask the delegate to perform in response
to user interaction. In Objective-C this is done through protocols.
You can think of a protocol as a contract between the view and its
data source or delegate.