🏠 Accueil
基準測試
📊 Tous les Benchmarks 🦖 Dinosaure v1 🦖 Dinosaure v2 ✅ To-Do List Apps 🎨 Pages Libres 🎯 FSACB - Showcase 🌍 Traduction
Modèles
🏆 Top 10 Modèles 🆓 Modèles Gratuits 📋 Tous les Modèles ⚙️ Modes Kilo Code
Ressources
💬 Prompts IA 📖 人工智能詞彙表 🔗 Liens Utiles
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.