分类10 用类来实现
2019-05-09 13:08:57 0 举报
设计模式
作者其他创作
大纲/内容
Command
execute
Interpreter 解释器模式
public class Invoker { private Command command = null; public void setCommand(Command command) { this.command = command; } public void runCommand() { command.execute(); }}
适合文法简单的解析场景解析性能不高
public class Client { public void assemble() { Receiver receiver = new Receiver(); Command command = new ConcreteCommand(receiver); Invoker invoker = new Invoker(); invoker.setCommand(command); }}
NonTerminalExpression
childExpressions
interpret(Context ctx)
Command 命令模式
MVC 里的 Action 就是 Command
分别创建:命令、调用方、接收方
AbsExpression
一个遥控电视的例子http://www.cnblogs.com/devinzhang/archive/2012/01/06/2315235.html
Invoker
Context
geetInfoToInterpret
Receiver
action
public class ConcreteCommand implements Command { private Receiver receiver = null; private String state; public ConcreteCommand(Receiver receiver){ this.receiver = receiver; } public void execute() { receiver.action(); }}
TerminalExpression
ConcreteCommand
receiver
0 条评论
下一页