命令模式 - 参数
我希望在分布式客户端/服务器环境中使用命令模式。本质上,接收器的“执行”方法需要采用各种参数,但是我读到每个命令类应该有一个统一的“执行”方法,该方法不应该透露接收器的底层功能。
我的问题是,如何通过命令类将调用参数从交换机传递到不同的接收器?有谁有一个简单的Java例子吗?我似乎找不到任何
感谢您的帮助。
I'm looking to use the command pattern in a distributed client/server environment. Essentially, the receivers 'execute' methods will need to take various parameters, however I read that each command class should have a uniform 'execute' method that should reveal nothing about the underlying functionality of the receivers.
My question is, how can I pass invocation parameters from switches into the different receivers via the command classes? Has anyone got a simple Java example? I can't seem to find any
Thanks indeed for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在构建命令实例时传递它们即可。
或者,如果您确实需要传递参数(因为它们代表工作状态而不是算法状态),那么您应该这样做并将其命名为“策略模式" ;)
Just pass them upon construction of the command instance.
Or if you really need to pass arguments (because they represent the work state and not the algorithm state), then you should just do so and call it "strategy pattern" instead ;)