MVC WRT WebApplications 的实际模式是什么? [英] What is the actual pattern for MVC WRT WebApplications?

查看:21
本文介绍了MVC WRT WebApplications 的实际模式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

混淆是因为互联网上漂浮着不同的 MVC 架构图:由于问题太宽泛,我想集中讨论用于 WebApplications 的 MVC.

说:Zend Framework.

example1: 可能是我见过的最好的.

示例 2:

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

<块引用>

我主要关注的是,视图如何与控制器交互模型反之亦然.

  • 视图是否应该直接与模型交互?
  • 模型是否应该直接更新对视图的任何更改?
  • example2 中的图表是否是对 MVC 的误解,因为它看起来像是 MVP()(WEB)="https://stackoverflow.com/users/1114171/tom-ingram">PDF).指向:Tom Ingram(谢谢).

    文章来自:约翰·迪肯 (John Deacon) 是一名讲师和作家.面向对象的分析与设计:一种实用主义方法.(有关作者的更多信息,请参阅关于作者 此处 )

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

    三部分:

    模型-视图-控制器:

    <块引用>

    我们将应用程序/领域不变的本质称为模型(单数).在面向对象的术语中,这将由一组类组成,这些类对基础问题进行建模和支持,因此它们往往与问题本身一样稳定且长期存在.
    模型(类)应该知道多少与外部世界的连接?没有,绝对没有.

    模型-<代码>视图-控制器:

    <块引用>

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

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

    或者:

    • 新手视角,
    • 专家观点.

    尽管视图通常是图形化的,但并非必须如此.

    视图会了解模型的哪些信息?他们必须知道它的存在.他们必须了解它的本质.例如,bookingDate 输入字段可能会在某处显示或更改某个模型类的实例变量.

    模型-视图-<代码>控制器:

    <块引用>

    控制器是一个让你操作视图的对象.稍微简化一下,控制器处理输入,而视图处理输出.控制器最了解平台和操作系统.视图完全独立于它们的事件是来自 Microsoft Windows、X Windows 还是其他任何东西.

    而且,就像视图知道它们的模型但模型不知道它的视图一样,控制器知道它们的视图但视图不知道它的控制器.*

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

    *仔细阅读并消化.

    <小时>

    还有关于(通过它们):

    模型"混淆

    <块引用>

    Smalltalk 可以归功于发明和推广 MVC 架构.但它也可能被指责混淆了事情.该架构的一个更好的首字母缩写词是:MdMaVC.
    Md:领域模型.
    Ma:应用模型.

    &关于应该如何进行通信:

    <块引用>
    • 查看模型通信.
    • 模型(和控制器)以查看通信.
    • 应用模型到领域模型的通信.

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

    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.

    example 2:

    example 3:
                                        
    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:

    解决方案

    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:
                      

    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?.

    这篇关于MVC WRT WebApplications 的实际模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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