What are the examples of Interpreter design pattern in JDK?

Interpreter design pattern is used to evaluate sentences in a language. E.g. In SQL we can use it to evaluate a query by evaluating each keyword like SELECT, FROM, WHERE clause.

In an Interpreter implementation there is a class for each keyword/symbol. A sentence is just a composite of these keywords. But the sentence is represented by Syntax tree that can be interpreted.

In JDK there are many places where Interpreter design pattern is used. Some of these are as follows:

  • java.util.Pattern
  • java.text.Normalizer
  • Subclasses of java.text.Format: DateFormat, MessageFormat, NumberFormat
  • Subclasses of javax.el.ELResolver: ArrayELResolver, MapELResolver, CompositeELResolver etc.

Leave a Reply

Your email address will not be published. Required fields are marked *