`

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

分享到:
评论

相关推荐

    Thinking in Patterns _ Problem Solving Techniques using Java.

    - **命令:运行时选择操作 (Command: Choosing the Operation at Run-Time)** - 命令模式用于将请求封装成对象,以便使用不同的请求、队列或者日志来参数化其他对象。 - **策略:运行时选择算法 (Strategy: ...

    Mask 98 for PRwin98

    It carries this out using unique 'Run-time Monitoring and Manipulation Technology' (RMMT) developed over many years, and which has culminated in this highly original product. Mask for Windows - ...

    端口查看工具

    (product name, file description, and so on), the time that the process was created, and the user that created it. In addition, CurrPorts allows you to close unwanted TCP connections, kill the process ...

    ZendFramework中文文档

    1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 ... The MESSAGES metacommand 14.5.4.7. Using options to set metacommands for all rules 14.5.5. Adding Filter ...

Global site tag (gtag.js) - Google Analytics