- 浏览: 132005 次
文章分类
- 全部博客 (149)
- Java (41)
- 设计模式 (23)
- php (2)
- C++ (2)
- Linux (6)
- C (1)
- JavaEE (27)
- javascript (2)
- uplodify (1)
- Mybatis (2)
- Maven (4)
- Lucene (3)
- commons (1)
- Spring (7)
- SQL (3)
- mahout (1)
- MySQL (2)
- extjs4.2.1 (2)
- ubuntu (1)
- hadoop (1)
- hibernate (1)
- Spring JPA (2)
- JPA 2.0 (1)
- express (1)
- redis (2)
- angularjs (1)
- git (1)
- Python (1)
- logging (2)
最新评论
-
xlaohe1:
controller返回的是一个POJO对象,然后用@Resp ...
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
TRAMP_ZZY:
能帮到你,我也很高兴。
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
jobzjc:
第一段有帮到我。如果是非对象,Object方式传递的时候,第一 ...
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
TRAMP_ZZY:
dingran 写道为什么,我怎么就没找到System > ...
Ubuntu 12.04 设置 IBus 开机启动 -
dingran:
为什么,我怎么就没找到System >> Pref ...
Ubuntu 12.04 设置 IBus 开机启动
public interface Command { public void execute(); }
public class NoCommand implements Command { @Override public void execute() { } }
public class Light { public void on() { System.out.println("Light was on."); } public void off() { System.out.println("Light was offf."); } }
public class LightOffCommand implements Command { private Light light; public LightOffCommand(Light light) { this.light = light; } @Override public void execute() { this.light.off(); } } public class LightOnCommand implements Command { private Light light; public LightOnCommand(Light light) { this.light = light; } @Override public void execute() { this.light.on(); } }
public class Stereo { public void on() { } public void off() { } public void setCd() { } public void setRadio() { } public void setVolume() { } }
public class StereoOffWithCommand implements Command { public Stereo stereo; public StereoOffWithCommand(Stereo stereo) { this.stereo = stereo; } @Override public void execute() { this.stereo.off(); } } public class StereoOnWithCDCommand implements Command { private Stereo stereo; public StereoOnWithCDCommand(Stereo stereo) { this.stereo = stereo; } @Override public void execute() { this.stereo.on(); this.stereo.setCd(); this.stereo.setVolume(); } }
public class RemoteControl { Command[] onCommands; Command[] offCommands; public RemoteControl() { this.onCommands = new Command[7]; this.offCommands = new Command[7]; Command command = new NoCommand(); for (int i=0; i<7; i++) { this.onCommands[i] = command; this.offCommands[i] = command; } } public void setCommand(int slot, Command onCommand, Command offCommand) { this.onCommands[slot] = onCommand; this.offCommands[slot] = offCommand; } public void onButtonWasPushed(int slot) { this.onCommands[slot].execute(); } public void offButtonWasPushed(int slot) { this.offCommands[slot].execute(); } public String toString() { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("\n---------------Remote Control----------\n"); return stringBuffer.toString(); } }
public class RemoteLoader { public static void main(String[] args) { RemoteControl control = new RemoteControl(); Light light = new Light(); LightOnCommand command = new LightOnCommand(light); LightOffCommand offCommand = new LightOffCommand(light); Stereo stereo = new Stereo(); StereoOnWithCDCommand cdCommand = new StereoOnWithCDCommand(stereo); StereoOffWithCommand stereoOffWithCommand = new StereoOffWithCommand(stereo); control.setCommand(0, command, offCommand); control.setCommand(1, cdCommand, stereoOffWithCommand); control.onButtonWasPushed(0); control.offButtonWasPushed(0); }
发表评论
-
设计模式-享元模式(Flyweight)
2014-06-20 13:11 500使用共享对象可有效地支持大量的细粒度的对象。要求细粒度的对象 ... -
设计模式-桥接模式
2014-06-19 17:12 259将抽象和实现解耦,使得两者可以独立地变化。 桥接模式使用了 ... -
设计模式-状态模式
2014-06-16 10:37 370状态模式允许对象在内部状态改变时改变它的行为,对象看起来好像 ... -
设计模式-代理和动态代理模式
2014-06-13 14:57 4041.简单代理模式 interface Interface ... -
java 迭代器
2014-06-11 18:04 606public class ReversibleArrayL ... -
设计模式-内部类工厂模式
2014-06-10 23:33 499public interface Service { ... -
设计模式-迭代器模式
2014-06-10 14:37 426迭代器模式提供一种方法顺序访问一个聚合对象中的各个元素,而又 ... -
设计模式-模板方法
2014-06-05 13:00 322public abstract class Caffein ... -
设计模式-适配器模式
2014-06-03 22:14 400适配器模式将一个类的接口,转换成客户期望的另一个接口。适配器让 ... -
设计模式-工厂方法
2014-06-01 18:04 454public abstract class PizzaSt ... -
设计模式-观察者模式
2014-06-01 11:03 4351. 利用Java 内置的类和接口实现观察者模式 publ ... -
设计模式-策略模式
2013-12-16 12:50 445Define a family of algorithms ... -
设计模式-装饰模式
2013-12-16 12:49 415Attach additional responibili ... -
设计模式-责任链模式
2013-12-11 18:00 499Avoid coupling the sender of ... -
设计模式-命令模式
2013-12-08 15:11 399命令模式是一个高内聚的模式。 Encapsulate ... -
设计模式-中介者模式
2013-12-08 12:29 366在多个对象依赖的情况下,通过加入终结者角色,取消了多个对象 ... -
设计模式-建造者模式(生成器模式)
2013-11-20 11:35 494ArrayList 或者 HashMap 如果定义为类的成员 ... -
设计模式-模板方法模式
2013-11-20 10:45 416Define the skeleton of an algor ... -
设计模式-抽象工厂模式
2013-11-18 15:49 394Provide an interface for creati ... -
设计模式-工厂方法模式
2013-11-18 08:59 572Define an interface for creatin ...
相关推荐
设计模式-命令模式(讲解及其实现代码)
java常用设计模式-命令模式
【设计模式-命令模式实战之WCS详细设计与实现(三)】堆垛机控制示例
设计模式--命令模式java例子
JAVA-设计模式-行为型模式-命令模式
设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段...
值得学习的命令模式代码,会让你有一定的收获,并有详细的说明和代码解析。
命令模式 Command 设计模式 若理解有问题,还请大S指教。
c++设计模式-行为型模式-命令模式;qt工程 ;c++简单源码; 命令(Command)模式的定义如下:将一个请求封装为一个对象,使发出请求的责任和执行请求的责任分割开。这样两者之间通过命令对象进行沟通,这样方便将...
这是一个非常有趣的关于23种设计模式中命令模式和享元模式的例子。例子在命令模式的基础上进行重构以及使用享元模式优化。。
该PPT用于公司内部分享设计模式6---命令模式之用,言简意赅,形象生动.故此分享,希望大家一起学习
cpp代码-设计模式-命令模式
设计模式专题之(十四)命令模式---设计模式命令模式示例代码(python--c++)
NULL 博文链接:https://meng22623.iteye.com/blog/1149714
设计模式讲解-命令讲解,里面有多线程常用使用方法
设计模式学习笔记-命令模式