Detailed explanation mode (java language source code is not attached)

Interpreter pattern (the Pattern Interpreter) :

Definition of a language, which defines a grammar representation and define an interpreter, the interpreter uses the representation to interpret sentences in the language. (Given a language, define are presentation for its grammar along with an interpreter that uses there presentation to interpret sentences in the language.)

Introduction :

  1. It is an unusual design pattern;
  2. It is used to describe how to make a simple language interpreter, mainly used for the development of object-oriented language
    compilers and interpreters design;
  3. When we need to develop a new language, consider using an interpreter mode;
  4. Do not use an interpreter mode, there will be a lot of trouble later maintenance. In the project, you can use
    Jruby, Groovy, java js engine to replace the role of interpreter, to make up for lack of java language.

Development of common scenarios :

  1. EL expression style processing;
  2. Regex interpreter;
  3. SQL syntax interpreter;
  4. Mathematical expression parser, such as ready-made kit: Math Expression String Parser, Expression4J and so on.

If you want to know more design patterns, you can visit: Introduction Overview of design patterns and 23 kinds of design patterns

Guess you like

Origin blog.csdn.net/cui_yonghua/article/details/93460141