Card 07/ 07

RecapDifficulty: Advanced1 min

Recap: Applying SOLID Together

Diagnose by symptom, refactor behind tests, and stop where nothing is expected to change.

Applying SOLID is one design method, not five rules.

  • The principles support each other. Single responsibility finds the seams, dependency inversion makes them extension points, interface segregation keeps those small, and Liskov makes plugging in safe. Open/closed is the result.
  • Diagnose by symptom. Branches that grow with each case point to open/closed; a subclass that refuses points to Liskov; stubs point to interface segregation; a test that needs a server points to dependency inversion; a class changed by two teams points to single responsibility.
  • Refactor behind tests. Pin today's behaviour first, then make one structural change and run the tests, and repeat.
  • The same three questions design new code: who asks for changes, what varies, and what the policy needs.
  • Python changes the form, not the principles. Duck typing makes many interfaces implicit; declare a Protocol or ABC at boundaries others implement.
  • Stop where nothing is expected to change. An extension point nobody uses is a cost, not a safeguard.