简体   繁体   English

这是命令模式吗?

[英]Is this the command pattern?

I have a MVP Gui and now I would like to define certain Actions or Commands (Modify, Save, Close, ...) for certain views. 我有一个MVP Gui,现在我想为某些视图定义某些操作或命令(修改,保存,关闭等)。

Is there an easy way to do this? 是否有捷径可寻? Should I provide Commands for each View? 我应该为每个视图提供命令吗?

The easiest way is to have a factory where all your command objects are instantiated. 最简单的方法是在工厂中实例化所有命令对象。 So if you have a open Job Command all the views would goto the factory and pull out the Open Job Command object, instantiate it, and then execute it. 因此,如果您具有打开的Job Command,则所有视图都将进入工厂并拉出Open Job Command对象,实例化它,然后执行它。 If you need to fix a bug or change the Open Job Command there only one spot you have to do it for all the Views. 如果您需要修复错误或更改“打开作业命令”,则只需要对所有视图执行一次操作即可。

With that being said there will be some commands that will probably be unique to each View. 话虽如此,有些视图可能对于每个视图都是唯一的。 Despite that you may want to still encapsulate those in a command object as you can easily implement Undo/Redo with everything going through command objects. 尽管如此,您仍可以将它们封装在命令对象中,因为您可以轻松地通过命令对象执行撤消/重做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM