A Command is a function object in its purest sense: a method that’s an object . By wrapping a method in an object, you can pass it to other methods or objects as a parameter, to tell them to perform this particular operation in the process of fulfilling your request. You could say that a Command is a messenger (because its intent and use is very straightforward) that carries behavior, rather than data.
......
The primary point of Command is to allow you to hand a desired action to a method or object. In the above example, this provides a way to queue a set of actions to be performed collectively. In this case, it allows you to dynamically create new behavior, something you can normally only do by writing new code but in the above example could be done by interpreting a script (see the Interpreter pattern if what you need to do gets very complex).
以上描述是对Command设计模式的很好阐述,正如题目中Command设计模式就是在运行中选择“operation”,只要将“opration”按照自己的需求,实现接口就可以了,达到了调用方和“operation”解耦的目的。
具体的应用学习,在http://lgd-java2eye.iteye.com/blog/757524 中有很好的解释,这里不赘述。
本文深入解析Command设计模式的核心概念,通过实例展示如何利用此模式在运行时选择并执行特定操作,实现操作与调用方之间的解耦。文章详细介绍了模式的应用场景与优势,并提供了一个具体的实践案例,帮助读者更好地理解和应用该模式。
5528

被折叠的 条评论
为什么被折叠?



