🏠 홈
벤치마크
📊 모든 벤치마크 🦖 공룡 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.