Refactoring with Solid
Refactor the provided code snippet to strictly adhere to SOLID principles and Clean Code guidelines.
- Category
- Software Development & Coding
- Output
- Markdown
- Fields
- 3
- software-development
- code-review
- best-practices
- code-structure
- architecture
- code-fix
- technical-writing
Prompt
You are an expert software engineer and code refactoring specialist. Your task is to refactor the provided code snippet to strictly adhere to SOLID principles and Clean Code guidelines.
Input code:
```Programming language
Code to refactor
```
Instructions:
1. Analyze the code for violations of each SOLID principle:
- Single Responsibility: Identify classes or functions handling multiple concerns and propose splits.
- Open/Closed: Show how to make the code extensible without modifying existing implementations.
- Liskov Substitution: Verify and correct inheritance hierarchies so derived classes can safely replace base classes.
- Interface Segregation: Break fat interfaces into smaller, client-specific ones.
- Dependency Inversion: Abstract concrete dependencies and invert control where appropriate.
2. Provide the fully refactored code.
3. Present a clear Before/After comparison.
4. Explain each significant change, explicitly mapping it to the relevant SOLID principle and Clean Code concept.
5. Use only the information in the provided snippet. Do not invent external libraries, APIs, or business logic. If the code lacks necessary context (e.g., missing dependencies, unclear business rules), flag it in a short "Open questions" list instead of guessing.
6. Adjust the technical depth of your explanations to match Explanation depth (if provided). If not specified, default to an intermediate level.
Output structure:
- Refactored Code: The complete, updated source code.
- Before/After Comparison: Sequential code blocks highlighting key structural changes.
- Change Explanations: Bulleted list mapping each modification to a specific SOLID principle or Clean Code guideline.
- Open Questions: (Only include if the input lacks necessary context) A concise list of ambiguities or missing details that need clarification.
Return the response in Markdown.
How to use this prompt
- Fill in the fields above. Required ones are marked with *.
- Check the prompt preview: your answers appear highlighted in place.
- Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
More Software Development & Coding prompts
- Bug Fix Brief for an AI AgentConvert raw bug reports into precise, unambiguous execution briefs tailored for AI coding agents.
- Caching Strategy DesignerDesign a robust, production-ready caching strategy for the specified feature, endpoint, or data flow.
- Database Schema Designer NormalizedProduce a production-ready, normalized relational schema with precise constraints, justified indexes, and practical migration guidance.
- Production Error Log TriageROLE: You are a senior on-call SRE and incident response engineer specializing in production debugging.
- Bug Diagnosis and FixYou are an expert software engineer and debugging specialist.
- Conventional Commit Message WriterROLE: You are a senior software engineer and version control specialist dedicated to maintaining clean, standardized, and highly readable Git history.