MVC与观察者模式 [英] MVC vs. Observer Pattern

查看:160
本文介绍了MVC与观察者模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在StackoverFlow上提出了一个关于MVC的问题:可以在桌面应用程序开发中使用MVC设计模式/架构模式吗?



根据提供的答案,我开始研究关于如何在Windows窗体应用程序中实现。我来了以下CodeProject文章: http://www.codeproject.com/KB/ cs / model_view_controller.aspx



在本文下面的评论中,某些用户认为(虽然这是一篇很好的文章),实际上是观察者模式。 首先,但不太重要的是,任何人都同意或不同意这一点,为什么?



关于第二个更重要的问题:我试图在.NET中构建一个小任务列表程序。这将是非常微小,希望快。一般来说,这样一个项目的架构是什么?观察者模式或MVC模式?还是另一种模式?



谢谢

解决方案

(这篇文章不是MVC AFAIK的一个例子,原因是没有控制器..如果你问我的话,它更接近于.net数据绑定。)

MVC不是Observer模式。 MVC关注分离问题。模型,视图和控制器都做一个工作,并相信其他人做他们的工作。在某种程度上,控制器指导视图,并告诉它如何对变化做出反应(Pure MVC)。控制器还适当地与模型进行交互(其职责是封装数据并执行约束/规则)。在MVC中,控制器是所有活动的起始点 - 用户输入首先由控制器接收。但是,有诸如MVP之类的变体,用户输入的变量首先被视图接收,然后被推送/同步。



观察者模式是您想要观看另一个对象以进行状态更改的位置。所以你可以说.net事件遵循观察者模式



如果它真的很小,忘记了模式,只是编写代码,而不用担心架构...按照启发式/良好设计原则





如果遇到设计问题,或者开始搞乱,那么请加入模式营。


I've recently asked a question on StackoverFlow about the MVC: Can the MVC Design Pattern / Architectural pattern be used in Desktop Application Development?

Based on the answer provided I started research on how this would be implemented in a Windows form Application. I came upon the following CodeProject article: http://www.codeproject.com/KB/cs/model_view_controller.aspx

In the comments below the article, certain users argue that (although this is a good article) it is actually the observer pattern. First, but less important, question is does anyone agree or disagree with that and why?

Regarding the second and more important question: I'm trying to build a small task list program in .NET. It will be very tiny and hopefully fast. In general, what would be a better architecture for such a project? The Observer Pattern or the MVC Pattern? Or another pattern?

Thank you

解决方案

(The article is not an example of MVC AFAIK for the simple reason that there is no controller.. it is more close to .net data binding if you ask me.)
MVC is not the Observer pattern. MVC is concerned with separation of concerns. The Model, the View and the Controller all do one job and trust the others to do theirs. In a way, the Controller 'directs' the view and tells it how to react to a change (Pure MVC). The controller also interacts with the model appropriately (whose responsibility is to encapsulate data and enforce constraints/rules). In MVC, the controller is the starting point for all activities - user input is received by the controller first.. However there are variants like MVP, where the user is input is received by the view first and then pushed/synched with the presenter.

The Observer pattern is where you want to watch another object for a change in state. So you could say .net events follow the observer pattern

If its really tiny, forget about patterns and just code it up without worrying about the architecture... Follow the heuristics/principles of good design

If you run into design issues or it starts to get all messy, then bring in the pattern battalions.

这篇关于MVC与观察者模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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