June 2018
Intermediate to advanced
348 pages
8h 45m
English
The Visitor implementation has to posses some idea of the structure of the Composite. In some instances of Composite implementation, there will be scores of Visitors needs to be implemented. Moreover, applying transformations and filters on nodes are bit difficult in the case of Visitor interfaces. The GOF pattern catalog has an Iterator pattern that can be used to navigate a sequence of items. The problem is: How can we linearize a hierarchy for processing using the Iterator pattern? Most hierarchies can be flattened to a list, sequence, or stream by writing a Visitor implementation for that purpose. Let us write a flattening Visitor for the said task.
Take a look at the following code:
Read now
Unlock full access