How do SOLID principles relate to YAGNI and DRY?
Answer
YAGNI (You Ain't Gonna Need It) and DRY (Don't Repeat Yourself) are complementary principles that must be balanced with SOLID. Tension exists: SOLID (especially OCP) encourages designing extension points even before you need them, which can conflict with YAGNI (only build what's needed now). The resolution is to apply SOLID reactively: when you see a second concrete variation or a second reason to change, that's the signal to introduce an abstraction (the Rule of Three). DRY eliminates duplication, but over-applying it can lead to premature abstractions that violate SRP by combining things that change for different reasons. Martin Fowler's advice: follow DRY when duplication represents the same knowledge; allow duplication when it represents different knowledge that happens to look the same currently.
Previous
What is "interface pollution" and which principle prevents it?
Next
How does SRP apply at the module/package level?
More SOLID Principles Questions
View all →- Intermediate How would you refactor a class that violates SRP?
- Intermediate How does the Strategy pattern support OCP?
- Intermediate What are the conditions for LSP compliance?
- Intermediate How does ISP prevent "fat interfaces"?
- Intermediate What is the difference between DIP and dependency injection containers?