在理想的MVC中,视图应该知道模型吗? [英] In ideal MVC should the view know the model?

查看:70
本文介绍了在理想的MVC中,视图应该知道模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于理想还是原始的MVC解释 http://heim.ifi.uio.no/~trygver /themes/mvc/mvc-index.html

My question is about the ideal or the original MVC interpretation http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html

由于MVC的目标是减少依赖关系,因此View是否应该知道模型?那么什么能防止它发胖并直接调用模型方法而不问控制器呢?

As MVC goal is to reduce dependencies, should the View knows the Model ? Then what would prevent it to become fat and call directly Model Methods without asking Controller ?

更新:当我阅读下面的答案时,我将举一个具体的例子:

Update: as I read answer below, I'll take a concrete example:

比方说,您创建了一个复杂的计算器(不仅仅是一个简单的计算器,比如说股票市场的期权定价器).它只需要输入诸如股价,利率,波动性之类的信息即可.那么为什么我只需要输入变量,为什么还要创建一个包含视图中方法的整个模型的引用呢?

Let's say you create a complex calculator (not just some simple one let's say an option pricer for stock market). It only needs input like stock price, interest rate, volatility. So why would I create a reference to the whole model which contains the methods from the view since I ONLY need these input variables ?

为什么在视图中发生某些更改时不仅仅通知控制器,然后仅使用输入回调视图中的方法?

Why the controller would not just be notified when something change in the view and then callback a method in the view with the input only ?

例如,在这里我看到视图"具有对整个模型的引用:

For example here I see the View has a reference to the whole model:

http://leepoint.net/notes-java/GUI/structure/40mvc.html

private CalcModel m_model;

推荐答案

视图不应该知道 business 模型,这取决于控制器.但是,视图应该了解 data 模型.它还必须怎么呈现呢?

The view should not know about the business model, that's up to the controller. The view should however know about the data model. How else must it present it?

这篇关于在理想的MVC中,视图应该知道模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆