设计模式之六:命令模式(简单实现(餐厅点餐模拟流程))
2012-10-01 11:27
696 查看
工程名称:
命令接口:CommandInSimple 下载目录:http://www.cnblogs.com/jrsmith/admin/Files.aspx ,CommandInSimple.zip
打开电灯的具体命令对象:
遥控器:
利用遥控器开灯的简单测试:
命令接口:CommandInSimple 下载目录:http://www.cnblogs.com/jrsmith/admin/Files.aspx ,CommandInSimple.zip
package com.jyu.command; /**命令接口*/ public interface Command { public void execute(); }
打开电灯的具体命令对象:
package com.jyu.command; public class LightOnCommand implements Command { Light light; public LightOnCommand(Light light) { this.light = light; } @Override public void execute() { light.on(); } }
遥控器:
package com.jyu.command; public class RemoteCOntrolTest { /** * @param args */ public static void main(String[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.setCommand(lightOn); remote.buttonWasPressed(); } }
利用遥控器开灯的简单测试:
package com.jyu.command; /**遥控器*/ public class SimpleRemoteControl { Command slot; public SimpleRemoteControl() { } public void setCommand(Command command) { this.slot = command; } public void buttonWasPressed(){ slot.execute(); } }
package com.jyu.command; public class Light { public void on(){ System.out.println("The Light is on..."); } public void off(){ System.out.println("The Light is off..."); } }
相关文章推荐
- 设计模式之六:命令模式(餐厅点餐模拟流程)
- 设计模式之二:观察者模式(简单实现(气象站模拟流程))
- 简单设计模式实现业务逻辑与流程逻辑的分离
- 简单设计模式实现业务逻辑与流程逻辑的分离
- 设计模式之Iterator:简单模拟java中集合类的实现
- 设计模式之四:简单工厂(披萨店生产披萨模拟流程)
- 简单工厂设计模式-模拟磁盘打开文件
- 资源池设计模式 (Resource Pool)和数据池的简单实现
- 游戏开发设计模式之命令模式(unity3d 示例实现)
- 设计模式--命令模式 C++实现
- Head First 设计模式 (六) 命令模式(Command pattern) C++实现
- Head First 设计模式 (六) 命令模式(Command pattern) C++实现
- 设计模式应用之使用COMPOSITE模式实现流程(三)
- C#基础:抽象类和抽象方法实现多态以及简单工厂设计模式的语法
- php简单实现单态设计模式的方法分析
- 简单模拟Comparator-策略设计模式-马士兵设计模式教程
- 设计模式:浅析 抽象工厂、工厂方法、简单(静态)工厂 java实现
- 模板方法设计模式简单实现
- 协议设计:如何实现一个最简单的通信协议(线程模拟)
- 设计模式——策略模式:会员价格体系的简单实现