iPhone Application Tutorial
Delegation is a pattern where one object periodically sends messages to another object specified as its delegate to ask for input or to notify the delegate that an event is occurring. You use it as an alternative to class inheritance for extending the functionality of reusable objects. In this application, the application object tells its delegate that the main start-up routines have finished and that the custom configuration can begin. For this application, you want the delegate to create an instance of a controller to set up and manage the view. In addition, the text field will tell its delegate (which in this case will be the same controller) when the user has tapped Return.
…
Model-View-Controller
The Model-View-Controller (or “MVC”) design pattern sets out three roles for objects in an application.
Model objects represent data such as SpaceShips and Rockets in a game, ToDo items and Contacts in a productivity application, or Circles and Squares in a drawing application. In this application, the data is going to be very simple—just a string—and it’’s not actually used outside of a single method, so strictly speaking it’’s not even necessary. It’’s the principle that’’s important here, though. In other applications the model will be more complicated and accessed from a variety of
locations.
View objects know how to display data and may allow the user to edit the data. In this application you need a main view to contain several other views—a text field to capture information from the user, a second text field to display text based on the user’’s input, and a button to let the user tell us that the secondary text should be updated.
Controller objects mediate between models and views. In this application, the controller object will take the data from the input text field, store it in a string, and update a second text field appropriately. The update will be initiated as a result of an action sent by the button.