命令模式
来源:互联网 发布:国联证券软件下载 编辑:程序博客网 时间:2024/05/24 06:17
public interface Command{void process(int[] target);}public class ProcessArray{public void process(int[] target,Command cmd){cmd.process(target);}}public class CommandTest{public static void main(){ProcessArray pa=new ProcessArray ();int[] target=new {1,2,3,4};pa.process(target,new PrintCommand());pa.process(target,new AddCommand());}}public class PrintCommand implements Command{public void process(int[] target){//..........}}public class AddCommand implements Command{public void process(int[] target){//..........}}
通过一个command接口让ProcessArray类和具体的 “处理行为分离”,只有等到调用ProcessArray的process方法时,传入一个真正的Command实例,才确定对数组的处理行为
0 0
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 拿来主义:觉得不错和大家分享-----实训数据库开发应用——SQL查询
- CryENGINE3初探Entities (一)----使用Lua创建一个自定义Entity并为其添加节点
- 【算法设计与分析】5、最长公共子序列
- 【算法设计与分析】6、最大字段和
- HTTP 服务器开发(Java)--HTTP请求
- 命令模式
- 【算法设计与分析】7、0/1背包问题,动态规划
- Android call requires API level解决之刃
- 世界阻燃剂前景分析
- codeforce 277.5 A
- poj.1008
- LeetCode OJ 之 Populating Next Right Pointers in Each Node (为每个结点填充右指针)
- 素数
- [LeetCode] Count and Say