MVC模型
來自wiki翻譯了半天,發(fā)現(xiàn)有人早就翻譯了伶授,但是略有不同彰檬。后來看到阮一峰的關(guān)于mvc的說明,他說東西一般都很清楚谎砾,什么時(shí)候才能有他那樣的本事啊逢倍。
寒冬 http://www.cnblogs.com/winter-cn/p/4285171.html
總感覺自己對于controller和view的界限有點(diǎn)模糊。
MVC是針對有用戶交互的軟件架構(gòu)模式景图,它分成三個(gè)部分较雕,model,view,controller。
Components 組成
The central component of MVC, the model, captures the behavior of the application in terms of its problem domain, independent of the user interface.The model directly manages the data, logic and rules of the application.
模型(Model)是MVC的主要組件挚币,捕獲在問題領(lǐng)域的應(yīng)用程序的行為亮蒋,與用戶界面獨(dú)立。模型直接管理應(yīng)用的數(shù)據(jù)妆毕,邏輯慎玖,規(guī)則。
A view can be any output representation of information, such as a chart or a diagram. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants.
視圖(View)可以是信息的任何輸出笛粘,比如chart或者diagram趁怔。同樣信息具有多個(gè)視圖是可能的,比如管理層的條形圖和會計(jì)人員的表格視圖薪前。
The third part, the controller, accepts input and converts it to commands for the model or view.
第三部分是控制器(controller),接受輸入润努,將之轉(zhuǎn)化為模型和視圖的命令。
Interactions交互
In addition to dividing the application into three kinds of components, the model–view–controller design defines the interactions between them.
除了將應(yīng)用劃分成三個(gè)不同的組件示括,mvc設(shè)計(jì)還定義了他們之間的交互铺浇。
A model stores data that is retrieved according to commands from the controller and displayed in the view.
模型從控制器的命令檢索存儲的數(shù)據(jù)并展示給視圖層。
A view generates new output to the user based on changes in the model.
視圖基于模型的改變輸出新的內(nèi)容垛膝。
A controller can send commands to the model to update the model's state (e.g. editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g. by scrolling through a document).
控制層向模型發(fā)送命令鳍侣,更新模型的狀態(tài)(比如編輯文檔),它同樣能向相關(guān)聯(lián)的視圖發(fā)送命令來改變視圖的展示(比如文檔滾動(dòng))
Use in web applications Web應(yīng)用的使用
Although originally developed for desktop computing, model–view–controller has been widely adopted as an architecture for World Wide Web applications in major programming languages. Several commercial and noncommercial web frameworkshave been created that enforce the pattern. These software frameworks vary in their interpretations, mainly in the way that the MVC responsibilities are divided between the client and server.
雖然最先是從桌面系統(tǒng)發(fā)展出來的丁稀,但是mvc的架構(gòu)被互聯(lián)網(wǎng)應(yīng)用廣泛地接受,一些商業(yè)和非商業(yè)的網(wǎng)絡(luò)框架采用了這個(gè)模式。他們在解釋上有些不同倚聚,主要是將mvc的責(zé)任劃分為客戶端和服務(wù)器端线衫。
Early web MVC frameworks took a [thin client]
(https://en.wikipedia.org/wiki/Thin_client) approach that placed almost the entire model, view and controller logic on the server. This is still reflected in popular frameworks such as Ruby on Rails, Django, ASP.NET MVC and Express. In this approach, the client sends either hyperlink requests or form input to the controller and then receives a complete and updated web page (or other document) from the view; the model exists entirely on the server.
早期的mvc框架采用“瘦客戶端”的方法將整個(gè)模型,視圖秉沼,控制邏輯都放在了服務(wù)器端桶雀,這個(gè)反應(yīng)在了類似 Ruby on Rails,Django,ASP.net MVC 以及Express上面矿酵。 在這些方法中唬复,客戶端發(fā)送整個(gè)超鏈接請求或者表單輸入給控制層然后為視圖提供接收整個(gè)或者重新更新的網(wǎng)頁(或者其他文檔),模型完全存在于服務(wù)器全肮。
As client technologies have matured, frameworks such as AngularJS, EmberJS, JavaScriptMVC and Backbone have been created that allow the MVC components to execute partly on the client (also see Ajax).
當(dāng)客戶端的技術(shù)成熟的時(shí)候敞咧,類似AngularJS、EmberJS辜腺、JavascriptMVC休建、Backbone等創(chuàng)建了允許MVC部分在客戶端執(zhí)行的框架(參見Ajax).