Visitor Pattern Lab 1
Lab Assignment: Adding a New Document Type
You have been given a document processing system that uses the Visitor pattern to perform operations on different document types. Your task is to add a new document type called ImageDocument
to the system and ensure it is compatible with the existing visitor infrastructure.
Requirements:
Implement a new class called
ImageDocument
that represents an image document. TheImageDocument
class should implement theDocument
interface and provide its own implementation of theaccept
andgetTitle
methods.Modify the
Main
class to include an instance ofImageDocument
and update the existing loops to include the new document type when applying the visitors.Test your implementation by creating instances of different document types, including the
ImageDocument
, and applying the print visitor and export visitor.
Note:
You can assume that the existing classes (
DocumentVisitor
,PrintVisitor
,ExportVisitor
,Document
,TextDocument
,SpreadsheetDocument
,PresentationDocument
, andMain
) are already implemented correctly.You can use the existing code provided in the previous example as a starting point for your implementation.