四个设计模式的帮派如何融入MVC范式? [英] How do Gang of Four Design Patterns fit into the MVC paradigm?

查看:200
本文介绍了四个设计模式的帮派如何融入MVC范式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经有一段时间了,我刚刚开始看到我如何在开发工作中更加刻意地加入其中的一些。但是,在本书开头,我仍然对MVC的处理感到困惑,并且与本书的其余部分有什么关系。



我工作的大多数框架与 - Spring,Yii,ASP.NET甚至Objective-C Cocoa(UIKit) - 适应MVC范例。我得到MVC,因为对我来说,这是一个有用的方法来分类对象,以及它们应该如何消息或互相交互。另外,这些框架也是强制它的,即使你没有考虑到MVC的方式。



我也觉得我明白了这个前提>设计模式:他们真的不喜欢子类化,他们喜欢抽象的接口,他们努力松散耦合。我不能说我完全理解所有的模式,或者它们是如何有用的,但我感觉到它。



我的问题是这样的: MVC和设计模式之间的相互作用?在MVC应用示例的第一章中他们得到了什么?某些设计模式是否与MVC范式无关?我不知道,例如,Command模式如何适应MVC。这似乎是非常有用的,但是我们是否创建一个 CommandModel CommandController 发送到其他控制器?我们只是按照书中的规定创建一个 Command 对象吗?基本上,我想知道MVC和设计模式的想法是否完全不相交,我只是不明白,或者是否存在不符合模具的模式。

解决方案

我的个人意见是MVC是Observer模式的简化版本,它是中介模式的简化版本。



MVC :一个模型,一个视图,Controler管理他们之间的沟通。



观察者模式:一个模型,多个视图(观察者/订阅者),发布商管理通信



中介模式:几个不同的模型,几个视图和调解员管理它们之间的通信。


I've mulled over Design Patterns for some time now and I am just starting to see how I might actually begin incorporating some of these more deliberately in my development work. However, I am still confused about their treatment of MVC in the beginning of the book and how it relates to the rest of the book.

Most of the frameworks I have worked with - Spring, Yii, ASP.NET, and even Objective-C Cocoa (UIKit) - cater to the MVC paradigm. I get MVC because to me it is a useful way of classifying objects and how they should message or interact with each other. Plus, these frameworks kind of force it upon you even if you are not setting out to think in the MVC way.

I also feel that I understand the premise of Design Patterns: they really don't like subclassing, they love abstract interfaces, and they strive for loose coupling. I can't say I fully understand all of the patterns yet or how they are useful, but I am getting a feel for it.

My question is this: what is the interplay between MVC and design patterns? What were they getting at in the first chapter of the book with the MVC application example? Are certain design patterns just not relevant in the MVC paradigm? I wonder, for example, how the Command pattern is supposed to fit into MVC. It seems incredibly useful, but do we create a CommandModel and CommandController to send to other controllers? Do we just create a Command object as prescribed in the book? Basically, I am wondering if the ideas of MVC and Design Patterns are wholly disjoint and I just don't understand, or if there are some patterns that do not fit into the mold.

解决方案

My personnal opinion is that MVC is a simplified version of the Observer Pattern which is a simplified version of the Mediator Pattern.

MVC: One Model, One view, the Controler manages the communication between them.

Observer Pattern: One Model, Multiples views ( observers/subscribers ), and the publisher manages the communication

Mediator Pattern: Several different Models, Several views, and the mediator manages the communications between them.

这篇关于四个设计模式的帮派如何融入MVC范式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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