19-Command: choosing the operation at run-time

      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 中有很好的解释,这里不赘述。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值