SOLID Principles — Practice Quiz
Work through each question. Reveal the answer when you're ready to check.
A UserService class has methods: createUser(), sendWelcomeEmail(), exportUsersToCSV(), and validatePassword(). Which methods violate SRP, and how would you fix it?
You have a ShapeAreaCalculator that uses switch/case for Circle, Rectangle, and Triangle. Explain why this violates OCP and refactor it.
A Bird class has a fly() method. Penguin extends Bird. Why does this violate LSP, and how do you fix it?
What is the "fat interface" anti-pattern, and how does ISP solve it?
Why does DIP make unit testing easier? Demonstrate by writing a test for an OrderService that uses DIP vs one that doesn't.
Rank the SOLID principles from "most commonly violated" to "least commonly violated" in typical codebases and explain why.
