为什么MVC范例最适合Web应用程序? [英] Why is the MVC paradigm best suited for web applications?

查看:129
本文介绍了为什么MVC范例最适合Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相当确定我的教授会问我为什么选择在我的Web应用程序中使用MVC.

I'm fairly certain my professor will ask me why I chose to use MVC for my web application.

说实话,我是MVC的新手.我读到有关它的信息,正在使用它构建一个博客应用程序,我认为以这种方式解决问题是非常合乎逻辑的.

Truth be told, I'm new to MVC. I read about it, I'm building a blog application using it, I think it's very logical to approach a problem this way.

但是为什么呢? O_O我画了一个空白.比说构建N层应用程序更合适?

But why? O_O I draw a blank. How is better suited than say, building an N-tier application?

推荐答案

好吧,基本上是:关注点分离在使用级别上,而不是在物理级别上.

Well, basically: separation of concerns on the usage level, not the physical level.

引用基于MVC的PoEAA

MVC将用户界面交互分为三个不同的角色.

MVC splits user interface interaction into three distinct roles.

使用MVC,您可以将表示形式(V,C)与域逻辑(M)分开,还可以将UI行为(C)与UI显示(V)分开.这比将所有三个问题混合为一个要容易得多,并且还可以促进重用和测试.它使您可以更好地解决复杂性.

With MVC , you are separating presentation (V, C) from the domain logic (M) and you also separate UI behavior (C) from UI display (V). This is much more maintainable than intermingling all three concerns into one and it also fosters reuse and testing. It allows you to better tackle complexity.

这仅适用于Web应用程序.它适用于具有域逻辑和UI的任何应用程序.话虽如此,我不会说MVC是Web应用程序的最适合模式.如果您只想在网络上放置一个联系表,那么一个全页脚本就足够了.如果您只有一堆静态页面,那么MVC也是过大的.因此,就像使用任何模式一样,它取决于您要解决的问题.

This is nothing that just applies to Web Applications. It is suitable for any applications with domain logic and a UI. With that said, I wouldn't say MVC is the best-suited pattern for a web app though. If all you wanna do is put, say, a Contact Form on the web, then an all-in-one-page script would be sufficient. If you only got a bunch of static pages, MVC is overkill too. So like with any patterns, it depends on the problem you want to solve.

对于第n层,经典" MVC并未预见到它在Web上的使用.由于UI的显示发生在浏览器和远程服务器上的控制器中,因此Web上的MVC始终也是多层体系结构,因此从一开始就在用例和物理上有所不同. MVC只是不关心它发生在哪里.

As for the n-tier, the "classic" MVC did not foresee it's use on the Web. With the presentation of the UI happening in the browser and the controller on a remote server, MVC on the web is always also a Multi-Tier architecture, hence the difference between usecase and physical in the beginning. MVC is just not concerned where it happens.

另请参阅:

  • What is MVC and what are the advantages of it?
  • MVC VS N-Tiers

这篇关于为什么MVC范例最适合Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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