Code Style Enforcer (DRY & SOLID)

A prompt that asks an AI to review and refactor code to eliminate repetition (DRY) and align with SOLID principles for better software design.

  • 🤖 ChatGPT, Claude, Gemini
  • 🗂️ Coding

Last verified: write-up checked

Prompt by PickleBoxer · Original source (opens in a new tab)

Code Style Enforcer (DRY & SOLID) — prompt preview

The prompt

prompt
Review the following code and refactor it to make it more DRY and adopt the SOLID programming principles.

[INSERT YOUR CODE HERE]

What it is

Code Style Enforcer is a prompt that asks the AI to refactor code with two specific goals: eliminating repetition (Don't Repeat Yourself) and applying the SOLID principles -- Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. These are foundational software engineering principles that lead to more maintainable, extensible, and testable code. This prompt is most useful for developers who want to improve the design of working code. It goes beyond surface-level formatting and targets structural issues: classes that do too much, functions that are copy-pasted with minor variations, tight coupling between modules, and rigid designs that are hard to extend. The prompt is particularly valuable as a learning tool. By seeing how an AI applies DRY and SOLID to your own code, you develop intuition for recognizing these patterns in future work. Ask the AI to explain which principle each change addresses for maximum educational value.

Who it's for

  • Developers
  • Software engineers focused on code quality and design patterns

Requirements

Requirements

  • Any AI chatbot (ChatGPT, Claude, Gemini)

برومبت يطلب من الذكاء الاصطناعي مراجعة الكود وإعادة هيكلته لإزالة التكرار وتطبيق مبادئ SOLID للتصميم البرمجي.

Examples

From the source

Prompt
prompt
Review the following code and refactor it to make it more DRY and adopt the SOLID programming principles.

[INSERT YOUR CODE HERE]

Expected output: From PickleBoxer's dev-chatgpt-prompts collection on GitHub.

Pros & cons

Pros

  • Pro:Applies well-known software engineering principles systematically rather than relying on intuition
  • Pro:Helps developers learn DRY and SOLID through practical, applied examples of their own code

Cons

  • Con:Strict SOLID adherence can lead to over-abstraction with many small classes that are harder to navigate
  • Con:The AI may introduce design patterns that add complexity without clear benefit for small or simple codebases

Tips

  • Ask the AI to annotate which SOLID principle each change addresses so you learn the reasoning
  • Provide the full class or module rather than isolated snippets for better single-responsibility analysis
  • Combine with unit tests to verify the refactored code maintains the same behavior