🏠 Início
Avaliações
📊 Todos os Benchmarks 🦖 Dinossauro v1 🦖 Dinossauro v2 ✅ Aplicações To-Do List 🎨 Páginas Livres Criativas 🎯 FSACB - Showcase Definitivo 🌍 Benchmark de Tradução
Modelos
🏆 Top 10 Modelos 🆓 Modelos Gratuitos 📋 Todos os Modelos ⚙️ Kilo Code
Recursos
💬 Biblioteca de Prompts 📖 Glossário de IA 🔗 Links Úteis
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.