Processing a structure with the visitor pattern
The patterns we've seen thus far organize the construction of objects and the execution of operations. The next pattern we'll look at is specially made to traverse and perform operations on hierarchical structures.
In this recipe, we'll be looking at the visitor pattern.
Getting ready
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
Additionally, this recipe assumes that you've completed the previous recipe, Assembling customized instances with builders. If not, complete that recipe first.
How to do it...
- Open your command-line application and navigate to your workspace.
- Copy the
09-02-assembling-instances-with-builders
folder to a new09-04-processing-a-structure-with-the-visitor-pattern
directory.
- Add a class named
MissionInspector
tomain.js
. Create avisitor
method that calls a corresponding method for each of the following types:Mission...