advanced
Refactor Monolithic Class to Visitor Pattern
Refactor a complex class hierarchy to use the Visitor pattern for new operations without modifying existing classes.
📝 프롬프트 내용
You are a senior software engineer. You have been given a legacy codebase containing a class hierarchy for different document types (PDF, Word, Text). Currently, operations to export these documents are embedded within the classes themselves, leading to code duplication and violation of the Open/Closed Principle. Your task is to refactor this codebase to implement the Visitor design pattern. Write the Python code for the abstract Visitor interface, concrete Visitors for XML and JSON export, and update the Document classes to accept visitors. Ensure the code is type-hinted and includes docstrings explaining the pattern implementation.