解释器模式
字数: 0

相关概念

Interpreter Pattern: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

实现代码

理论模型 → CFG 语法树
现实例子 → 根据规则(年龄和职业)来判断一个人是否符合特定条件(贷款资格)

表达式

具体表达式

上下文

测试类

Q & A

When should I use this pattern?
In daily programming, it is not needed very much. Though in some rare situations, you may need to work with your own programming language to define specific protocols. In a situation like this, this pattern may become handy.
But before you proceed, you must ask yourself about the return on investment (ROI).
What are the advantages of using an interpreter design pattern?
  • You are very much involved in the process of how to define grammar for your language and how to represent and interpret those sentences. You can change and extend your grammar also.
  • You have full freedom over how to interpret these expressions
2023 - 2026