MVC 和命令模式
好吧,这有点愚蠢。我正在尝试使用 MVC 和命令模式。这些问题主要涉及到哪里 放置代码。
在MVC模式中,Commands在哪里实例化? 它们是由控制器创建的,还是完全包含在模型中,或者两者都不包含。
顺便说一句,如果不需要撤消/重做,应该使用命令模式。
问候
Ok, this is kinda dumb. I'm trying to wrap my head around the use of
the MVC and Command Patterns. The questions basically concern where to
place code.
In the MVC pattern, where are the Commands instantiated?
Are they created by the Controller, or are they contained fully in the Model or neither.
BTW, Should one be using the Command pattern if there is no need of undo/redo.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然根据应用程序的需求/复杂性有许多变化,但您通常会发现它们是在控制器中实现的。这是一篇关于在 MVC 架构中使用命令模式的精彩文章。我不确定您正在构建什么类型的应用程序,但这里还有一些资源显示了不同应用程序堆栈上的实现。
http://java.sun.com/blueprints/ guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
http ://msdn.microsoft.com/en-us/library/ff647590.aspx
http: //www.phpwact.org/pattern/model_view_controller
While there are many variations based on the needs/complexity of an application, you typically find them implemented in the Controller. Here is a great article on using the Command pattern in an MVC architecture. I'm not sure what type of application you are building, but here are a few more resources that show implementations on different application stacks.
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
http://msdn.microsoft.com/en-us/library/ff647590.aspx
http://www.phpwact.org/pattern/model_view_controller
在 MVC 应用程序中实现命令模式取决于您的具体需求。默认情况下,控制器不创建任何命令。如果您需要在 MVC 应用程序中实现命令模式,您必须自己完成。
您可以在控制器中实现命令,也可以在单独的服务层中执行。它不应该在模型中,因为命令模式是行为的并且应该独立于模型。
To implement Command pattern in an MVC application depends on your specific need. Controller does not create any Command by default. If you need to implement command pattern in a MVC application you have to do it on your own.
You can either implement the commands in the Controller or can do in a separate Service layer. It should not be in Model as Command pattern is behavioural and should be independent of model.