惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
About on SuperTechFans
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
G
Google Developers Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
Cloudbric
Cloudbric
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
H
Heimdal Security Blog
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Latest news
Latest news
I
Intezer
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
月光博客
月光博客
T
Threatpost
博客园 - 【当耐特】
S
Schneier on Security
P
Privacy International News Feed
G
GRAHAM CLULEY
T
Tenable Blog
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
博客园 - Franky
Engineering at Meta
Engineering at Meta
美团技术团队
S
Secure Thoughts
T
Troy Hunt's Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - BearOcean

LOG.ZS.0001.基于Freetype的游戏字体渲染优化思路 const 和指针 C++ 下啥时候用struct, 啥时候用class C++ 和 Java 中的变参 解决站点关键数据,状态数据,无须持久化数据的一些思路 BS程序代码与安全与基本攻击/防御模式 Struts 实现的I18N Ant 阅读笔记 进度,效率,与个人事务管理 Personal Task 1.0 MySql与Java的时间类型 数据挖掘概述 解决Thread 的关闭问题和参数传递时想到的办法. .Net标准控件与自定义控件(2) ToolTipButton 内网聊天工具FreeChat 2.0 FreeChat 2.0 ...大改 模型和架构 局域网聊天工具FreeChat 1.0 开发日志 内网聊天工具FreeChat Beta 为Socket写的附加方法 .Net 事件
Command 模式
BearOcean · 2006-04-29 · via 博客园 - BearOcean

  Command 模式

大多数类都是一组方法和相应的一组变量的结合。而Command 仅仅由一个具有唯一方法的接口组成。简单的几乎可笑。所以有人说该模式具有功能分解的意味,根本是对面向对象的亵渎。

Public interface Command             

{

 public void do();

}

 

就是这样形成了最简单的Command模式,具体的命令实现了Command接口的Do方法。
所以Command的拥有者不需要知道Comman具体干了什么,只需要调用与之绑定的
Command.do方法就可以了。

 已一个模拟实现门开关,和敲击的程序为例,就可以运用Command模式。

可以这样阐述这个问题,程序创建一个DoorUI的实例。该实例可以假象成一个WebForm或则WinForm 他能接受用户的输入。

他能够探知用户是在开门,还是关门,还是敲门。甚至是其他操作。
当他接收到用户的输入。便生成一个Command实例。例如有人试图开门:
Command Cmd =new OpenCommand();
然后DoorUI触发一个事件表示接收到了一个用户命令,并且将该命令传输给Application

EventGetCommand (aCmd);
当Application收到该事件以后,直接调用Cmd.do()方法便可。
ADoor.Cmd =aCmd;
ADoor.Cmd.do();
这个是最简单的例子。目前我对Command的理解也限制于这个层面。当我们需要添加一个按门铃的操作时 只需要编写一个实现Command接口的新类:RingCommand就可以了。
除此以外,Command模式也可以很好的解决事务操作以及Do和UnDo等问题。
其真正的使用价值,还是要在实际的项目中才能体现出来。