MVC模式与旧式3层图案的主要优点是什么? [英] What are the main advantages of MVC pattern over the old fashioned 3-layer pattern

查看:221
本文介绍了MVC模式与旧式3层图案的主要优点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑在我的新项目中使用MVC模式,我可以清楚地看到能够将数据层(模型)更接近表示层(视图)的主要优点,这将允许一点点的应用速度增加。但除了性能方面,MVC还有其他的优势,就是视图逻辑数据分层类型模式?



编辑:
对于那些有兴趣的人,我刚刚上传了一个我创建的示例PHP代码来测试使用MVC。我目的是省略所有的安全检查,使代码更容易阅读。请不要批评太多,因为我知道它可以是更多的精致和先进的,但是 - 它的工作!我会欢迎提出问题和建议:以下是链接: http:/ /www.sourcecodester.com/sites/default/files/download/techexpert/test_mvc.zip

解决方案

引用为MVC优势的关注点的分离实际上也是3层/ 3层系统的进步。也有,业务逻辑是独立的,可以从不同的表示层使用。



主要的区别是,在经典的MVC中,模型可以引用返回到视图。这意味着当数据更新时,模型可以将该数据推回到可能的多个视图。主要的例子是桌面应用程序,其中数据以多种方式可视化。这可以像表格和图表一样简单。表中的更改(一个视图中的更改)首先通过控制器推送到模型,然后将其推回到图形(另一个视图)。然后,图表会自动更新。



由于桌面开发正在下降,许多程序员只能在某些网络变体中与MVC联系,例如通过Java EE中的JSF。



在这些情况下,模型几乎从未有过该视图的引用。这是因为网络主要是基于请求/响应,并且在请求被提供之后,服务器不能发送附加信息。即从模型推送到客户端的更新将是无意义的。使用反向ajax /彗星这是变化的,但许多基于Web的MVC框架仍然没有充分利用这一点。



因此,在基于Web的MVC的情况下,典型的M,V和C之间的三角形比较少,MVC变体实际上比真MVC更接近于n层模型。



另请注意一些Web MVC框架在M,V和C之间有一个称为支持bean(Java / JSF)或后面的代码(ASP.NET)的中间管道部分。在JSF中,控制器由框架提供,并且该视图通常不直接绑定到模型,而是使用该支持bean作为中介。支持bean非常纤薄,基本上只是从模型预取数据,并将模型特定消息(例如,例外)转换为特定于视图的消息(例如一些人类可读文本)。


I am contemplating about using an MVC pattern in my new project and I can clearly see the main advantage of being able to put the data layer (the model) a little closer to the presentation layer (the view), which will allow a little increase in application speed. But apart from performance stand point are there any other advantages of MVC over the view-logic-data layered type pattern?

EDIT: For those who's interested I just uploaded a sample PHP code that I created to test the use of MVC. I purposly omitted all the security checks to make the code a little easier to read. Please don't critisize it too much, because I know it could be a lot more refined and advanced, but nevertheless - it works!!! I will welcome questions and suggestions: Here is the link: http://www.sourcecodester.com/sites/default/files/download/techexpert/test_mvc.zip

解决方案

The separation of concerns that's quoted as being an advantage of MVC is actually also an advance of a 3-layer/3-tier system. There too, the business logic is independent and can be used from different presentation tiers.

A main difference is that in classic MVC the model can have a reference back to the view. This means when data is updated the model can push this data back to possibly multiple views. The prime example is a desktop application where data is visualized in multiple ways. This can be as simple as a table and graph. A change in the table (which is a change in one view) is first pushed via the controller to the model, which then pushes it back to the graph (the other view). The graph then updates itself.

Since desktop development is on the decline, a lot of programmers have only come in touch with MVC in some web variant, e.g. via JSF in Java EE.

In those cases the model almost never has a reference to the view. This is because the web is mainly request/response based and after a request has been served, the server cannot send additional information. I.e. an update pushed from the model to the client would be meaningless. With reverse ajax/comet this is changing, but many web based MVC frameworks still don't fully utilize this.

Thus, in the case of web based MVC, the typical "triangle" between M, V and C is less there and that MVC variant is actually closer to an n-tier model than 'true' MVC is.

Also note that some web MVC frameworks have an intermediate plumbing part between M, V and C called a backing bean (Java/JSF) or code behind (ASP.NET). In JSF the controller is provided by the framework, and the view often doesn't bind directly to the model but uses this backing bean as an intermediary. The backing bean is very slim and basically just pre-fetches data from the model one way and translates model specific messages (e.g. exceptions) into view specific messages (e.g. some human readable text).

这篇关于MVC模式与旧式3层图案的主要优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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