MVC设计模式读书笔记

 这个笔记来自《Advanced ActionScript 3 with Design Patterns》一书,是去年11月份读的。幸好当时做了一些笔记。不然现在MVC章节的所有部分都要重新读一遍了。虽然很多高手都觉得设计模式没有什么用处,但是MVC这一模式还是很实用的。

BTW,抵触设计模式的人,好像并不抵触MVC。大笑

  包包

如果要做苹果的app,这个也应该是要掌握的。因为我看斯坦福的apple教程里面,第一个就是对MVC的解释。如果要做WebGame客户端,这个也应该是要掌握的。因为我经历的项目就是MVC架构的(每一个具体的子系统是一个MVC)。这本书对MVC的解释非常到位,看了之后能够让你彻底搞清楚MVC到底是怎么回事。

 

MVC Design(Architectural) Pattern 

括号中的字也表明,MVC也可以作为客户端的架构指导。

The basic principle of this pattern is to distinguish between the data and the presentation of that data.

  包包 
1,Understanding MVC Elements

The MVC pattern is composed of three subsystems as indicated by the name: the model, the view, and the controller. 
(1)Model : The defining aspects of the model are that it acts as a storehouse for data and that it exists independently of the view and the controller. The model should never have a reference to the view or the controller. This is absolutely essential to the functioning of the MVC pattern because the model's independence is what creates the flexibility in the MVC pattern.

(2)View : The view is the visual display portion of the user interface subsystem. The view uses the data from the model to draw itself. The key to understanding the view is to understand that it consists only of the visual elements and the logic necessary to read the model data and use it as required by the user interface.

(3)Controller : The controller is the subsystem that is responsible for taking input (user input, for example) and updating the model and view as necessary. 


2,The Relationships between Elements
(1)Model必须保持与View、Controller的独立,也就是说Model不知道其他Elements的存在。A model can broadcast messages when the data changes. 但是Model在广播消息的时候并不知道谁在侦听。

(2)The view always knows about the model. The view interacts with the model in two ways: It listens for update messages, and it reads from the model. The view never writes to the model. Every view keeps a reference to its model. Because a view knows about its model but a model doesn't know about a view, a single model can act as the model for many views.

(3)The controller also knows about the model. The controller is responsible for updating the model when necessary based on user input or system events.

(4)The relationship between the controller and the view is very tightly coupled. Although it is possible to have a controller that uses several views, it is far more common that the relationship between view and controller is one-to-one. The view contains all the user interface elements through which the user interacts. Yet the controller is the element that responds to user input.(这里说View包括所有的用户界面,但是书中的例子,View只包括Model数据对应的界面,而与用户交互的界面比如文本框、按钮都是Controller提供的) In many, if not most, ActionScript applications, the view and the controller are one class. This variation of the MVC pattern is often called a Document View implementation of MVC.

(5)The most important key to the MVC pattern is that the model must be an independent object that does not have a reference to the view or controller. The view updates and redraws itself based on changes to the model.           包包

你可能感兴趣的:(读书笔记,设计,design,休闲,都)