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

Fill in the details

Paste the source code you want to improve.

Specify the language (e.g., Python, JavaScript, Java) for accurate syntax highlighting.

Choose how detailed the technical explanations should be.

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

  1. Fill in the fields above. Required ones are marked with *.
  2. Check the prompt preview: your answers appear highlighted in place.
  3. Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
See all Software Development & Coding prompts