MVC WRT WebApplications 的实际模式是什么?

发布于 2024-12-23 10:31:39 字数 1118 浏览 2 评论 0原文

造成混乱的原因是互联网上流传着不同的 MVC 架构图: 由于问题太宽泛,我想集中讨论用于 Web 应用程序的 MVC。

说:Zend Framework

example1:可能是我见过的最好的一个。 MVC

示例 2: MVC

示例 3:
             &n bsp;             MVC
模型-视图-控制器概念。实线表示直接关联,虚线表示间接关联(例如通过观察者)。

我主要关注的是视图如何与控制器交互以及视图如何与控制器交互。型号反之亦然。

  • 视图应该直接与模型交互吗?
  • 模型是否应该直接更新视图的任何更改?
  • 示例2中的图表是否是对 MVC 的误解,因为它看起来像是 MVP(1)(2)模式。

MVC 与 MVP 的示例: 在此处输入图像描述

The confusion is because of the different MVC architechture diagrams floating on the internet:
Since the question would be too broad I want to concentrate on the MVC's used for WebApplications.

Say: Zend Framework.

example1: Probably the best one I have seen.
MVC

example 2:
MVC

example 3:
                                    MVC
Model-view-controller concept. The solid line represents a direct association, the dashed an indirect association (via an observer for example).

What I am mainly concentrating is on, how the view interacts with controller(s) & model(s) vice versa.

  • Should the view interact directly with model(s)?
  • Should the model directly update any changes to the view(s)?
  • Is the diagram in example2 a misinterpretation of MVC as it looks like its a MVP(1)(2)pattern.

An example of MVC vs MVP:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

究竟谁懂我的在乎 2024-12-30 10:31:39

由于没有发布答案,我决定发布一个。这很大程度上是基于
模型-视图-控制器 (MVC) 架构 (WEB) (PDF)。指向者:Tom Ingram(谢谢)。

文章作者:
约翰·迪肯是一位讲师和作家。面向对象的分析与设计:务实的
方法。 (有关作者的更多信息,请参阅关于作者 此处

现在,最适合 MVC 架构的图是:
            MVC

三部分:

Model-View-Controller:

我们将应用程序/领域不变的本质称为模型(单数)。用面向对象的术语来说,这将由一组类组成,这些类模拟并支持底层问题,因此往往会像问题本身一样稳定且长期存在。
模型(类)应该对与外部世界的连接了解多少?没什么,绝对没什么。

模型-视图-控制器:

对于给定情况,在给定版本中,模型将有一个或多个接口,我们将其称为视图(复数)。
在面向对象的术语中,这些将由一组类组成,这些类为我们提供了模型的“窗口”(通常是实际的窗口),例如

  • GUI/小部件(图形用户界面)视图,
  • CLI(命令行界面)视图,
  • API(应用程序接口)视图。

或者:

  • 新手观点,
  • 专家观点。

虽然视图通常是图形化的,但它们不一定是图形化的。

视图会对模型了解什么?他们必须知道它的存在。他们必须了解其本质。例如,bookingDate 输入字段可能会在某处显示并可能更改某个模型类的实例变量。

模型-视图-控制器

控制器是一个可以让您操作视图的对象。过于简单化了,控制器处理输入,而视图处理输出。控制者最了解平台和操作系统。视图完全独立于其事件是否来自 Microsoft Windows、X Windows 还是其他。

正如视图知道它们的模型但模型不知道它的视图一样,控制器知道它们的视图但视图不知道它的控制器。*

控制器是 Smalltalk 特定的。它们不具有普遍意义,因此这里不做更深入的讨论。例如,在Java的Swing架构中,视图和控制器是组合在一起的(这在其他架构中经常这样做)。在 Swing 中,组合的视图/控制器称为委托。

*仔细阅读并消化。


还有关于(通过它们):

“模型”混淆

Smalltalk 可以说是 MVC 架构的发明者和推广者。但它也可能被指责混淆视听。该架构的更好缩写是:MdMaVC。
Md:领域模型。
Ma:应用程序模型。

&关于沟通应如何进行:

  • 查看模型通信。
  • 用于查看通信的模型(和控制器)。
  • 应用模型到领域模型的通信。

我认为这应该让我们非常清楚地了解 MVC 的实际模式是什么?

Since no answer was posted, I decided to post one. This is largely based on
Model-View-Controller (MVC) Architecture (WEB) (PDF) . Pointed to by: Tom Ingram (Thanks).

The article is by:
John Deacon is a lecturer and writer. Object-Oriented Analysis and Design: A Pragmatic
Approach. (for more on the author refer the section About the author here )

Now, the diagram best suited for the MVC architecture is:
                  MVC

The three parts:

Model-View-Controller:

We will call the unchanging essence of the application/domain, the model (in the singular). In object-oriented terms, this will consist of the set of classes which model and support the underlying problem, and which therefore will tend to be stable and as long-lived as the problem itself.
How much should the model (classes) know about the connection to the outside world? Nothing, absolutely nothing.

Model-View-Controller:

For a given situation, in a given version there will be one or more interfaces with the model, which we'll call the views (plural).
In object-oriented terms, these will consist of sets of classes which give us "windows" (very often actual windows) onto the model, e.g.

  • The GUI/widget (graphical user interface) view,
  • The CLI (command line interface) view,
  • The API (application program interface) view.

Or:

  • The novice view,
  • The expert view.

Although views are very often graphical, they don't have to be.

What will the views know about the model? They have to know of its existence. They have to know something of its nature. A bookingDate entry field, for example, might display, and perhaps change, an instance variable of some model class somewhere.

Model-View-Controller:

A controller is an object that lets you manipulate a view. Over-simplifying a bit, the controller handles the input whilst the view handles the output. Controllers have the most knowledge of platforms and operating systems. Views are fairly independent of whether their event come from Microsoft Windows, X Windows or whatever.

And, just as the views know their model but the model doesn't know its views, the controllers knows their views but the view doesn't know its controller.*

Controllers were Smalltalk specific. They are not of general interest and are not covered in any greater depth here. In Java's Swing architecture, for example, the view and the controller are combined (this is often done in other architectures). In Swing the combined view/controller is called the delegate.

*Read carefully and digest.


There is also about (go through them):

"Model" confusion

Smalltalk, then, can be credited with inventing and promoting the MVC architecture. But it could also be accused of confusing things. A better acronym for the architecture would be: MdMaVC.
Md: The domain model.
Ma: The application model.

& about how the communication should occur:

  • View to model communication.
  • Model (and controller) to view communication.
  • Application model to domain model communication.

I think this should give us a very clear picture of What is the actual pattern for MVC?.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文