当前位置: 首页 > news >正文

网站开发课程软件seo每日工作

网站开发课程软件,seo每日工作,黄冈网站seo,北京市海淀区住房和城乡建设委员会网站COMMAND 模式 command模式非常简单,简单到你无法想象的地方。 public interface Command {void execute(); } 这就是一个command模式的样子。也许你会觉得,这有点多此一举吗。但是当你使用他的时候,command模式就会闪现光华。 这样一个场景&a…

COMMAND 模式

command模式非常简单,简单到你无法想象的地方。

public interface Command {void execute();
}

这就是一个command模式的样子。也许你会觉得,这有点多此一举吗。但是当你使用他的时候,command模式就会闪现光华。

这样一个场景:经理张三叫leader王二去开发一个项目, 王二就安排李四 去开发这个功能A。 李四何时执行,怎么执行就是他自己的事情了。


UML图如上所示:
代码如下:
public interface CommandInterface {void execute();
}
public class ContractCommand implements CommandInterface {Member member;public ContractCommand(Member member) {this.member = member;}@Overridepublic void execute() {member.action();}
}
public class Member {public void action(){TraceLog.i();}
}

Leader,获取命令,然后执行命令。

public class Leader {CommandInterface commandInterface;public void setCommandInterface(CommandInterface commandInterface) {this.commandInterface = commandInterface;}public void executeCommand(){commandInterface.execute();}
}
public class Manager {public static void main(){Member m = new Member();CommandInterface c = new ContractCommand(m);Leader wang2 = new Leader();wang2.setCommandInterface(c);wang2.executeCommand();}
}

manager创建运行的平台。

这样命令模式就开启了。

Active Object

Active Object 模式

一开始蛮难理解这个模式的目的,而且GOF的23中经典模式里也没有这个模式。

/*** @author deman.lu* @version on 2016-06-02 14:45*/
public class ActiveObjectEngine {List<CommandInterface> itsCommands = new ArrayList();/*need to running in main thread, should check with synchronized*/public void addCommand(CommandInterface aCommand){itsCommands.add(aCommand);}public void run(){/*should running in background*/while (itsCommands.size() > 0){CommandInterface c = itsCommands.get(0);itsCommands.remove(0);c.execute();}}
}

这个就是ActiveObject的engine,2个函数。一个是把一条command添加到表里面。

另一个是一个循环,处理问题。仔细思考,这就是消费者,和生产者问题的变种。

but这里没有线程block的地方。先看完全部代码:

public class SleepCommand implements CommandInterface {@Overridepublic void execute() {Date currentTime = new Date();if (!started) {started = true;this.startTime = currentTime;this.engine.addCommand(this);} else {long elapsedTime = currentTime.getTime() - startTime.getTime();if (elapsedTime < SleepTime) {this.engine.addCommand(this);} else {this.engine.addCommand(this.wakeupCommand);}}}private CommandInterface wakeupCommand = null;private ActiveObjectEngine engine = null;private long SleepTime = 0;private Date startTime;private boolean started = false;public SleepCommand(long milliSeconds, ActiveObjectEngine e,CommandInterface wakeupCommand) {this.SleepTime = milliSeconds;this.engine = e;this.wakeupCommand = wakeupCommand;}}
public class DelayedTyper implements CommandInterface {private long itsDelay;private char itsChar;private static boolean stop = false;static String printStr = "";private static ActiveObjectEngine engin =new ActiveObjectEngine();static class StopCommand implements CommandInterface{@Overridepublic void execute() {DelayedTyper.stop = true;}}public static void Main(){engin.addCommand(new DelayedTyper(100, 'A'));engin.addCommand(new DelayedTyper(300, 'B'));engin.addCommand(new DelayedTyper(500, 'C'));engin.addCommand(new DelayedTyper(700, 'D'));CommandInterface stopCommand = new StopCommand();engin.addCommand(new SleepCommand(2000, engin, stopCommand));engin.run();TraceLog.i(printStr);}public DelayedTyper(long delay, char c){this.itsDelay = delay;this.itsChar = c;}@Overridepublic void execute(){printStr +=itsChar;if (!stop){DelayAndRepeat();}}private void DelayAndRepeat(){engin.addCommand(new SleepCommand(itsDelay, engin, this));}
}

结果如下:

ABCDAAABACABAADAABCAAABAADABCAAABAACDB

当DelayedTyper没有到执行的时间点的时候,启动SleepCommand。

这个很关键,

            if (elapsedTime < SleepTime) {this.engine.addCommand(this);} else {this.engine.addCommand(this.wakeupCommand);}

如果时间没到,就把自己加入到队列最后,等待下次执行。(此处没有用常见的线程block技术)

时间到了,就把wakeupCommand加入执行队列。

这里还有个关键是,没有stopcommand,命令会一直循环执行。

参考:

《敏捷软件开发》 Robert C. Martin 

转载于:https://www.cnblogs.com/deman/p/5553538.html

http://www.lbrq.cn/news/2613961.html

相关文章:

  • 专做进口批发的网站宁波seo外包优化公司
  • 中国网站建设世界排名网站免费下载安装
  • 网站建设文字资料seo综合查询怎么用
  • 农业网站怎么做网络优化主要做什么
  • 做网站需要域名嘉兴seo优化
  • 想自己做点飘纱素材到网站上买网站如何提升seo排名
  • 网页设计与网站建设 设计题100个常用的关键词
  • 这个百度的网站怎么做的成都新一轮疫情
  • 临朐网站制作哪家好semantic scholar
  • 广州建设银行网站首页2022年免费云服务器
  • 福建电信网站备案长春网站seo公司
  • 网站后台链接怎么做高州新闻 头条 今天
  • d?t网站模版温州seo网站建设
  • wordpress没有备案seo优化网络公司
  • erp软件怎么用搜索引擎优化培训中心
  • 网站备案 停站免费html网站模板
  • 威县网站建设无锡网站制作优化
  • 广州中小学安全教育平台企业整站优化
  • 视频源网站怎么做优化方案的格式及范文
  • 做视频网站seo怎么赚钱
  • wordpress发号系统巢湖seo推广
  • 做ui必要的网站最新最好的磁力搜索
  • 汕头模板建站软件网站seo优化报告
  • 内蒙古住房建设厅网站百度问一问人工客服怎么联系
  • 西安网站建设网络网站域名查询地址
  • 哪类型网站容易做找网络公司做推广费用
  • 重庆永川网站建设价格网站策划方案
  • 怎样重新运行wordpress四川seo推广公司
  • 工程建设信息官方网站做app找什么公司
  • 尤溪网站开发seo交流qq群
  • 笔试——Day30
  • 笔记学习杂记
  • 数据结构(三)双向链表
  • vllm启动Qwen/Qwen3-Coder-30B-A3B-Instruct并支持工具调用
  • Flask + HTML 项目开发思路
  • 13015计算机系统原理-速记宝典