🏠 首页
基准测试
📊 所有基准测试 🦖 恐龙 v1 🦖 恐龙 v2 ✅ 待办事项应用 🎨 创意自由页面 🎯 FSACB - 终极展示 🌍 翻译基准测试
模型
🏆 前 10 名模型 🆓 免费模型 📋 所有模型 ⚙️ 🛠️ 千行代码模式
资源
💬 💬 提示库 📖 📖 AI 词汇表 🔗 🔗 有用链接
advanced

Refactor Monolithic Class to Visitor Pattern

#refactoring #design-patterns #python #oop

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.