• Albert Bennett

Design Patterns: Interpreter

Updated: Jul 12, 2021

As always here is the link to the GitHub repo :)

If this post has helped you feel free to like, comment and share.

So for today's lesson... we are going to be going over the interpreter pattern.

So first of all what is it used for?

The interpreter pattern is useful for building rules in a logical manner. Such as for a handling grammar in a programming language.

In the diagram below you can see how this pattern works:

As you can see there is a bit to it... but, I'll go through it:

Client: This class defines the user of the pattern. In here trees of expressions are made to which, a context object is passed into to execute the expressions.

Context: This class is used to execute all of the expressions.

Expression Base: This is the base class of all expressions in the pattern.

Terminal Expression: Defines a single expression.

Non Terminal Expression: Defines an expression that can call other expressions.

Now, there are several updates that can/ should be done. Namely implementing binary tree of some sort, to better manage the expressions.

I hope this helps you understand the Interpreter pattern. Catch you on the flip side.

<< More Design Patterns

3 views0 comments

Recent Posts

See All