标签:
解释器模式,包含如下几类角色:
代码如下:
public class Context { private String value; public Context(){ this.value = "Init"; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
public interface Expression { public void interpret(Context context); }
public class OneExpression implements Expression { @Override public void interpret(Context context) { System.out.println("OneExpression interpret " + context.getValue()); } }
public class App { public static void main(String[] args) { Context context = new Context(); OneExpression expression = new OneExpression(); expression.interpret(context); } }
标签:
原文地址:http://www.cnblogs.com/Fredric-2013/p/4573484.html