2011年6月12日 星期日

Stanford CS193P Note-01

Design Strategies (設計策略): MVC

1. Divide(劃分) objects in your program into 3 "camps(營地)."
(1). Model = What your application is (but not how it is displayed)
(2). Controller = How your Model is presented(呈現) to the user (UI logic)
(3). View = Your Controller's minions(手下)


2. It's all about managing communication between camps

(1). Controllers can always talk directly to their Model.
(2). Controllers can also talk directly to their View.
(3). The Model and View should never speak to each other.


Controllers and View:
3. Can the View speak to its Controller?
   (1). Sort of. Communication is "blind" and structured.
   (2). The Controller can drop a target on itself.
   (3). Then hand out an action to the View.
   (4). The View sends the action when things happen in the UI.

4. Sometimes the View needs to synchronize with the Controller.
   (1). The Controller sets itself as the View's delegate.
   (2). The delegate is set via a protocol (i.e. it's "blind" to class). 

5. Views do not own the data they display.
   (1). So, if needed, they have a protocol to acquire(獲得) it.
   (2). Controllers are almost always that data source (not Model!).
   (3). Controllers interpret/format(詮釋/格式化) Model information for the View.


Controllers and Model:


6. Can the Model talk directly to the Controller?
(1). No. The Model is (should be) UI independent.
(2). So what if the Model has information to update or something?
(3). It uses a "radio station"-like broadcast mechanism(機制).
(4). Controllers (or other Model) "tune in"(收聽) to interesting stuff.
(5). A View might "tune in," but probably not to a Model's "station."


7. Now combine MVC groups to make complicated programs ...


沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。