設計模式之Interpreter(解釋器)
来源:互联网 发布:淘宝查看商品降价 编辑:程序博客网 时间:2024/04/27 21:20
Interpreter定義:
定義語言的文法 ,並且建立一個解釋器來解釋該語言中的句子。
Interpreter似乎使用面不是很廣,它描述了一個語言解釋器是如何構成的,在實際應用中,我們可能很少去構造一個語言的文法。我們還是來簡單的瞭解一下:
首先要建立一個介面,用來描述共同的操作。
public interface AbstractExpression {
void interpret( Context context );
}
再看看包含解釋器之外的一些全局資訊
public interface Context { }
AbstractExpression的具體實現分兩種:終結符運算式和非終結符運算式:
public class TerminalExpression implements AbstractExpression {
public void interpret( Context context ) { }
}
對於文法中沒一條規則,非終結符運算式都必須的:
public class NonterminalExpression implements AbstractExpression {
private AbstractExpression successor;
public void setSuccessor( AbstractExpression successor ) {
this.successor = successor;
}
public AbstractExpression getSuccessor() {
return successor;
}
public void interpret( Context context ) { }
}
posted on 2004年06月24日 8:13 PM
- 設計模式之Interpreter(解釋器)
- 設計模式之Interpreter(解釋器)
- 設計模式之Interpreter(解釋器)
- Behavioral模式之Interpreter模式
- C#设计模式之Interpreter
- 行为模式之三---Interpreter
- 【设计模式】之六Interpreter
- 设计模式之Interpreter解释器模式
- 设计模式之解释器模式,interpreter
- 设计模式之解释器模式(interpreter)
- 行为模式之解释器模式-INTERPRETER
- 设计模式之Interpreter模式(笔记)
- 设计模式之:解释器模式(Interpreter)
- 设计模式之解释器模式(Interpreter)
- 设计模式之Interpreter(解释器)
- 设计模式之Interpreter(解释器)
- 设计模式之Interpreter(解释器)
- 设计模式之Interpreter(解释器)
- web services的基本概念
- Java Bean 应用-预定构件(Inber 原创)
- 世界500强面试题(精彩选载)
- JSP设计模式
- 設計模式之Visitor
- 設計模式之Interpreter(解釋器)
- 設計模式之Mediator(仲介者)
- 設計模式之Mediator(仲介者)
- 設計模式之Strategy(策略)
- 設計模式之State
- 来天空漫步吧
- 設計模式之Chain of Responsibility(職責鏈)
- 設計模式之Command
- 新买了一块硬盘