advanced

Showing a principle in code

Demonstrate principles through small refactors: extracting responsibilities, narrowing interfaces, inverting dependencies, or deleting speculative layers.

Demonstrate principles with small, focused refactors interviewers can follow live: extract a class for SRP, introduce an interface for DIP, replace inheritance with composition, or delete a speculative layer for YAGNI. Before/after diffs should show clearer dependency direction and tests that got easier.

Keep changes minimal—one principle per example so causality stays obvious.

On interviews: walk through a 20-line refactor narrating which smell you address and how tests support the change.

Common pitfalls: huge rewrites in interviews, refactoring without tests, and renaming only without structural improvement.

The trade-off is time spent on cleanliness versus proving you can improve code safely under pressure.

Checklist:

  • One smell, one principle, one refactor.
  • Keep tests green throughout.
  • Explain dependency arrows after change.