MVC模型
来自wiki翻译了半天,发现有人早就翻译了,但是略有不同。后来看到阮一峰的关于mvc的说明,他说东西一般都很清楚,什么时候才能有他那样的本事啊。
寒冬 http://www.cnblogs.com/winter-cn/p/4285171.html
总感觉自己对于controller和view的界限有点模糊。
MVC是针对有用户交互的软件架构模式,它分成三个部分,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的主要组件,捕获在问题领域的应用程序的行为,与用户界面独立。模型直接管理应用的数据,逻辑,规则。
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。同样信息具有多个视图是可能的,比如管理层的条形图和会计人员的表格视图。
The third part, the controller, accepts input and converts it to commands for the model or view.
第三部分是控制器(controller),接受输入,将之转化为模型和视图的命令。
Interactions交互
In addition to dividing the application into three kinds of components, the model–view–controller design defines the interactions between them.
除了将应用划分成三个不同的组件,mvc设计还定义了他们之间的交互。
A model stores data that is retrieved according to commands from the controller and displayed in the view.
模型从控制器的命令检索存储的数据并展示给视图层。
A view generates new output to the user based on changes in the model.
视图基于模型的改变输出新的内容。
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).
控制层向模型发送命令,更新模型的状态(比如编辑文档),它同样能向相关联的视图发送命令来改变视图的展示(比如文档滚动)
Use in web applications Web应用的使用
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.
虽然最先是从桌面系统发展出来的,但是mvc的架构被互联网应用广泛地接受,一些商业和非商业的网络框架采用了这个模式。他们在解释上有些不同,主要是将mvc的责任划分为客户端和服务器端。
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框架采用“瘦客户端”的方法将整个模型,视图,控制逻辑都放在了服务器端,这个反应在了类似 Ruby on Rails,Django,ASP.net MVC 以及Express上面。 在这些方法中,客户端发送整个超链接请求或者表单输入给控制层然后为视图提供接收整个或者重新更新的网页(或者其他文档),模型完全存在于服务器。
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).
当客户端的技术成熟的时候,类似AngularJS、EmberJS、JavascriptMVC、Backbone等创建了允许MVC部分在客户端执行的框架(参见Ajax).