English 中文(简体)
MVC模式中的“模型”是什么?
原标题:What is the "model" in the MVC pattern?
  • 时间:2011-11-10 20:37:57
  •  标签:

因此,我对MVC模式进行了一些谷歌搜索,I m仍然无法确定“Model”部分的内容。 如何处理? 我对方案规划来说是一个新鲜事,因此,我可以认为,我的所有解释都与我的头部完全吻合。 请让我简单地解释一下。

Thanks

最佳回答

我最简单的描述是把它称为“数据”部分。 如果它必须处理获取或保存数据的问题,它就属于模型。 如果你有网络应用程序,该模型通常与数据库或档案系统互动。

问题回答

Model in MVC is a place where data presented by the UI is located. Therefore, it shouldn t be confused with Domain Model which serves as a skeleton that holds the business logic.

当然,对于一个小型应用,作为支持妇发基金行动的一个服务,这两个模式可以相同。 在一个真正的世界应用中,这些应用应当明确分开。

Controller is the one who talks to the application services and the Domain Model. It receives updates back from application services updating the Model which is then rendered by the View.

View renders the state hold by the Model, interprets User s input and it redirects it to the Controller. Controller then decides if the Model is going to be updated immediately or first the information is forwarded to application services.

模型可在较小项目中代表你的“主要模式”。 域网包括代表真正世界实体重新处理问题的类别。

In larger projects, the Domain Model should be separated out of the actual MVC application, and given it s own project/assembly. In these larger projects, reserve the "Model" (i.e. the "Models folder in the MVC project") for UI presentation objects (DTOs - Data Transfer Objects)

The model is respomnsible for managing the data in the application. This might include stuff like database queries and file IO.

这一观点显然是模板,控制者是业务逻辑。

The model is used to represent the data you are working with. The controller controls the data flow and actions that can be taken with the data. The view(s) visualize the data and the actions that can be requested of the controller.

简单例子:

一辆汽车是一种模型,它具有汽车(轮船、发动机等)的特性。

管制人员界定了在汽车上可以采取的行动:观看、洗衣、制造甚至诸如买卖等行动。

控制器将数据传递给既显示数据又有时让用户就数据采取行动的看法。 然而,请求采取的行动实际上由控制人员处理。





相关问题
热门标签