打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Command
public interface Command {
public void excute();
}


public class Light {
public void on() {
System.out.println("return on");
}
public void off() {
System.out.println("return off");
}
}

public class LightOnCommand implements Command{
private Light light;
public LightOnCommand(Light light) {
this.light = light;
}
@Override
public void excute() {
light.on();
}
}

public class SampleRemoteControl {
private Command command;
public void setComand(Command command) {
this.command = command;
}
public void buttonWarPressed() {
command.excute();
}
}

public class Test {

public static void main(String[] args) {
Light light = new Light();
Command command = new LightOnCommand(light);
SampleRemoteControl control = new SampleRemoteControl();
control.setComand(command);
control.buttonWarPressed();
}
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Command 命令模式
命令模式.
设计模式之命令模式(一)
乱砍设计模式之十
设计模式(十五)——命令模式(Spring框架的JdbcTemplate源码分析)
设计模式之命令模式(二)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服