Javaインプリメンテーションインタプリタモード


/**
 *            
 * @author stone
 *
 */
public interface Interpreter {
	
	public void interpret(Context context);  //   ,         ,          
}
public class XmlSaxInterpreter implements Interpreter {

	@Override
	public void interpret(Context context) {
		System.out.println("xml sax Interpreter:" + context.getData());
	}

}
public class XmlDomInterpreter implements Interpreter {

	@Override
	public void interpret(Context context) {
		System.out.println("xml dom Interpreter:" + context.getData());
	}

}
/**
 *             
 * @author stone
 *
 */
public class Context {
	private String data;
	
	public String getData() {
		return data;
	}
	
	public void setData(String data) {
		this.data = data;
	}
}
/*
 *    (Interpreter)  
 *       ,           ,        ,                 。        
 *     ,    、     、    ...
 *                     ,        、         ,
 */
public class Test {
	public static void main(String[] args) {
		Context context = new Context();
		context.setData("  xml  ");
		new XmlSaxInterpreter().interpret(context);
		new XmlDomInterpreter().interpret(context);
	}
}