命令模式
2017-09-25 15:08:12   0  举报             
     
         
 主要是根据Head First 设计模式画的类图
    作者其他创作
 大纲/内容
 LightOffCommand
  - light:Light 
  + LightOffCommand(Light)+ execute()
    Command
  + execute()
  StereoOnWithCDCommand
  - stereo:Stereo 
  + StereoOnWithCDCommand(Stereo )+ execute()   这里可以执行一系列Stereo动作
  第二阶段控制器,实现一组命令的执行第三阶段可以在Control里面添加撤销动作,这时要记住前一个命令是什么。第四阶段如果对象是有状态的比如电风扇是速度调控的,可以在电风扇对象中记录前一次的状态,撤销的时候做的动作使状态恢复到前一个状态就好了。第五阶段实现一个命令可以调控多个对象。比如一个命令同时关闭音响和灯。
  SimpleRemoteControl
  - slot:Command
  + SimpleRemoteControl()+ setCommand(Command)+ buttonWasPressed()
  LightOnCommand
  + LightOnCommand(Light)+ execute()
  第一阶段测试1.创建SimpleRemoteControl2.创建Light3.用Light创建LightOnCommand4.SimpleRemoteControl设置command4.执行+buttonWasPressed()我们可以看到LightOnCommand是某一类对象的某一个功能实现。需要指定对象执行某一个功能,看上去好像变的复杂了,而耦合还在。
  RemoteControl
  - onCommand:Command[]- offCommand:Command[]
   
 
 
 
 
  0 条评论
 下一页
  
   
   
   
   
  
  
  
  
  
  
  
  
 ![处理[命令+数据]](https://www.processon.com/chart_image/template/thumb/5505aa3be4b03108ad55e45b.png?tid=55059bd9e4b07f960cbd4b9d)