设计模式-命令模式
来源:互联网 发布:管理员权限安装软件 编辑:程序博客网 时间:2024/06/02 01:03
命令模式概述:
http://baike.baidu.com/link?url=xL1IdoM5a_exqMqs6WGIoee4CDDeqIWQXEfKNu8qa149gFuc8AV3L91sDRy3qNk7G0t8tW895NIXLg5JjvWWkq
- 例子:
public interface Commond {//命令接口 public void action(); //执行命令 }
// 命令接收者public class Receiver { public void back() {//返回行为 System.out.println("back ====="); } public void on() {//打开行为 System.out.println("on ====="); }}
public class BackCommond implements Commond {//返回的命令 private Receiver receiver; public BackCommond(Receiver receiver) { this.receiver = receiver; } @Override public void action() { receiver.back(); }}
public class OnCommond implements Commond {//打开的命令 private Receiver receiver; public OnCommond(Receiver receiver) { this.receiver = receiver; } @Override public void action() { receiver.on(); }}
public class Controller {//命令控制者 private Commond commond; public Controller(Commond commond){ this.commond = commond; } public void action(){ commond.action(); } }
public class Test { public static void main(String[] args) { Receiver receiver = new Receiver(); // Commond commond = new OnCommond(receiver); Commond commond = new BackCommond(receiver); Controller controller = new Controller(commond); controller.action(); }}
1 0
- 设计模式---命令模式
- 设计模式-命令模式
- 设计模式:命令模式
- 设计模式:命令模式
- 设计模式:命令模式
- 设计模式 命令模式
- 设计模式--命令模式
- 设计模式---命令模式
- 设计模式- 命令模式
- 设计模式---命令模式
- 设计模式 - 命令模式
- 【设计模式】【命令模式】
- 设计模式---命令模式
- 设计模式 - 命令模式
- 设计模式:命令模式
- 设计模式 - 命令模式
- 设计模式-命令模式
- 设计模式---命令模式
- XtraBackup导入
- 深度优先搜索 和问题 简单函数递归 “加 还是不加”
- 贪心算法-Best cow line-字典序问题
- linux下如何对串口编程
- Android 屏幕适配-图片
- 设计模式-命令模式
- 设计模式之策略模式
- 贝塞尔曲线
- 前端性能优化总结
- Android之Fragment(一)
- SQLite3 API编程手册
- 详解linux下的串口通讯开发
- JAVA---Merge Intervals
- nmap#2探测网关