MVC

pp4

In an object-oriented application, information isn't just bytes; objects encapsulate information along with methods for using the information. Each object within your applicaiton should fit into exactly one of the following subsystems:

Model:  The Model subsystem is composed of the objects that provide the unique cappabilities and indormation storage for an application. Model contain all of the rules for processing application data. It's critically important that the Model subsystem is able to stand alone without dependencies on either the View or Controller subsystems.

View:  

Controller:  The purpose of the Controller is to decouple the Model from the Views. User interaction with a View results in requests made to the Controller subsystem, which in turn may request changes to information in the Model. The Controller also handles data translation and formatting for presentation to a user. For example, a Model may store data in meters, but based on a user's preference, the Controller may convert the data to feet.

 

The primary purpose of MVC is to decouple the Model subsystem from the Views so that each can change independently.

Why Controller?

The answer is that Views tend to change much more often than Models. Not only are there potentially many Views, but it's the nature of user interfaces that they change based on customer feedback and evolving user interface standards. It's also sometimes important to change the Model without affecting all of the Views. The Controller subsystem provides insulation between the Model and the Views.

It's imprtant to use messaging approaches that minimize coupling. Ideally, neither the Model nor the View have dependencies on the Controller. For example, View objects often use the Target Action desin pattern from Chapter 17,"Outlets, Targets, and Actions." to avoid needing any information about the Controller objects that receive messages when the user interacts with user interface objects. Model objects often use the Notifications pattern in Chapter 14, "Notifiactions," to broadcast notification of Model Changes to anonymous interested objects that may be in the Controller subsystem.

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2013-02-08 16:38  Chansonyan  阅读(112)  评论(0)    收藏  举报

导航