Summary
In this chapter, we created a library for producing tabular reports in various formats. In the process, we learned about creating arbitrary hierarchies of objects in a tree-structured manner. We leveraged the composite pattern to implement our hierarchy. The composites were processed using the visitor pattern. We dealt with PDF and HTML output by writing PDFVisitor
and HTMLVisitor
classes. Incorporating a new output format is just a matter of writing a new visitor (say, SVGVisitor
), where one needs to map the contents of the document to the appropriate SVG tags. In the next chapter, we will learn about the interpreter pattern and the observer pattern by implementing a library that will help us plot arbitrary expressions as graphs.