架构更适合Web应用程序比MVC? [英] Architecture more suitable for web apps than MVC?

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

问题描述

我一直在学习Zend公司及其MVC应用程序结构,我的新工作,发现与它的工作只是困扰我的原因,我不能完全把我的手指上。然后我的研究过程中,我碰到如 MVC文章:没有银弹并的this播客。在播客的人做了一个很好的案例对MVC的Web应用程序的体系结构和钉了很多什么是窃听我的脑袋的。

I've been learning Zend and its MVC application structure for my new job, and found that working with it just bothered me for reasons I couldn't quite put my finger on. Then during the course of my studies I came across articles such as MVC: No Silver Bullet and this podcast on the topic of MVC and web applications. The guy in the podcast made a very good case against MVC as a web application architecture and nailed a lot of what was bugging me on the head.

然而,问题依然存在,如果MVC是不是真的非常适合Web应用程序是什么?

However, the question remains, if MVC isn't really a good fit for web applications, what is?

推荐答案

这一切都取决于你的编码风格。这里的秘密:这是不可能用PHP编写的经典MVC

It all depends on your coding style. Here's the secret: It is impossible to write classical MVC in PHP.

任何框架,它声称可以是骗你的。现实情况是,框架本身甚至无法实现MVC - 你的code能。但是,这不是一样好营销策略,我猜。

Any framework which claims you can is lying to you. The reality is that frameworks themselves cannot even implement MVC -- your code can. But that's not as good a marketing pitch, I guess.

要实现一个经典的MVC它需要你有持久的模型开始。此外,模型应通知查看更改(观察者模式),在你的香草PHP页面这太是不可能的(你可以做一些接近经典的MVC,如果你使用的插座,但这是不切实际的,真正的网站)。

To implement a classical MVC it would require for you to have persistent Models to begin with. Additionally, Model should inform View about the changes (observer pattern), which too is impossible in your vanilla PHP page (you can do something close to classical MVC, if you use sockets, but that's impractical for real website).

在网络的发展实际上有4 MVC等为灵感的解决方案:

In web development you actually have 4 other MVC-inspired solutions:


  • Model2的MVC :查看正在请求从模型数据,然后决定如何使它和模板使用。控制器负责改变着视图和模型的状态。

  • Model2 MVC: View is requesting data from the Model and then deciding how to render it and which templates to use. Controller is responsible for changing the state of both View and Model.

MVVM :控制器被交换出去的ViewModel,负责查看的期望和模型的逻辑之间的转换。从控制器,转换请求,使模型可以把它理解查看请求数据。

MVVM: Controller is swapped out for a ViewModel, which is responsible for the translation between View's expectations and Models's logic. View requests data from controller, which translates the request so that Model can understand it.

大多数情况下,当你有过任何意见或模型层没有控制你会使用这个。

Most often you would use this when you have no control over either views or the model layer.

MVP (框架称之为PHP的MVC):presenter从型号请求信息,收集它,修改它,并把它传递到被动视图

MVP (what php frameworks call "MVC"): Presenter requests information from Model, collects it, modifies it, and passes it to the passive View.

要探索这种模式,我建议你使用本出版物开始。它会详细解释一下。

To explore this pattern, I would recommend for you begin with this publication. It will explain it in detail.

HMVC (或PAC):从Model2的不同与执行子控制器的控制能力。每次用M,V和C的黑社会本身你获得模块化和可维护性,但性能命中一些支付。

HMVC (or PAC): differs from Model2 with ability of a controller to execute sub-controllers. Each with own triad of M, V and C. You gain modularity and maintainability, but pay with some hit in performance.

反正。底线是:你还没有真正使用MVC

Anyway. The bottom line is: you haven't really used MVC.

但是,如果你生病了所​​有MVC状结构,你可以看看:

But if you are sick of all the MVC-like structures, you can look into:


  • 事件驱动架构

  • N层架构

再有就是总是 DCI 的范例,但是,当应用到PHP它有一些问题(你不能投在PHP类..不无丑陋黑客)。

And then there is always the DCI paradigm, but it has some issues when applied to PHP (you cannot cast to a class in PHP .. not without ugly hacks).

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

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