扯一扯命令模式
老早就看过命令模式,但是具体项目使用起来,理解的不是很好,最近有点小感悟,闲扯下
命令模式的核心:包装命令处理作为一个类存在 --core1
提供统一接口--core2
一般情景中能看到的命令模式:
struts2就是基于命令模式的框架,请求--响应这种web方式,一个path对应一个action处理
path就是命令,对应的action就是命令,而且还提供了统一的接口exe
但是通常用插件实现零配置,这个用annotation方式也实现了统一的处理,具体没细看
public interface Action { /** * Where the logic of the action is executed. * * @return a string representing the logical result of the execution. * See constants in this interface for a list of standard result values. * @throws Exception thrown if a system level exception occurs. * Application level exceptions should be handled by returning * an error value, such as Action.ERROR. */ public String execute() throws Exception; }