The interpreter pattern is a design pattern that specifies how to evaluate sentences in a language.
The basic idea is to have a class for each symbol (terminal or nonterminal) in a specialized computer language. The syntax tree of a sentence in the language is an instance of the composite pattern and is used to evaluate (interpret) the sentence for a client.
Purpose
Building a mini-language interpreter that can be used to create scriptable applications.
Example
Unit converter.
Implementation
The Strategy pattern
The strategy pattern (also known as the policy pattern) is a software design pattern that enables selecting an algorithm at runtime.
Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use.
Purpose
Identifying algorithms in a system and encapsulating them into their own types.
Example
Car selection algorithm based on the day of the week.
Implementation
The Observer pattern
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
Purpose
Creating hooks for alerting disparate objects about system events.
Example
You have a list. When there is a change, you need invoke update() on each element in a list.
Implementation
The Visitor pattern
The visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existent object structures without modifying the structures.
Example
Applying an operation to all the nodes in a tree of objects.
Implementation
The Command pattern
The command pattern is a software design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
Purpose
Creating a simple interface to complex or variable systems.
Example
On and off the lamp.
Implementation
The Null Object pattern
In object-oriented computer programming, a null object is an object with no referenced value or with defined neutral ("null") behavior. The null object design pattern describes the uses of such objects and their behavior (or lack thereof).
Example
Using non-operational objects in place of null values.
Implementation
Summary
In this post, we looked at patterns that help us to get things done.