Explain the decision and prove the behavior
Answer before opening the guide. Then solve the exercise, test an edge case and explain when you would not introduce the abstraction.
SRP: reasons to change
A service validates, saves and emails an order. Which changes belong together?
Practice in Kotlin →Answer guide
Group behavior by the stakeholder or policy that changes it. Extract persistence and notification boundaries when they vary independently. SRP does not mean one method per class.
OCP: a useful extension point
Would you add an interface or a sealed when for a new pricing rule?
Practice in Kotlin →Answer guide
A function parameter can be enough for one varying calculation. Prefer an interface for independently extensible behavior; use a sealed hierarchy when the variants are deliberately closed and exhaustive handling is valuable.
LSP: preserve the contract
A subtype throws for a method promised by its interface. Does compiling prove substitutability?
Practice in Kotlin →Answer guide
No. Verify behavior: accepted inputs, postconditions and invariants. Do not strengthen preconditions or weaken promised results. Write the same contract tests for every implementation; do not require all implementations to have identical internal code.
ISP: contracts shaped by clients
Should a basic printer implement scan() and throw UnsupportedOperationException?
Practice in Kotlin →Answer guide
Separate printing and scanning capabilities. The print client needs only the printing contract. Kotlin interface delegation can compose capabilities, but splitting interfaces is justified by client needs, not by an arbitrary method-count rule.
DIP: testable policy boundaries
How would you test order placement without a database or email service?
Practice in Kotlin →Answer guide
Inject small contracts through the constructor and use in-memory fakes. Dependency injection is a wiring technique; DIP is the dependency direction. Assert outputs and essential side effects, and separately integration-test the real adapters.
Patterns and code review · 45-minute mock
5 min: identify the requested change and observable behavior. 20 min: refactor with Strategy, Decorator or an injected function; justify the choice. 10 min: test boundaries, effects and failures. 10 min: review naming, null-safety, mutability, coupling and complexity. Avoid !! without a contract, do not silently swallow exceptions, and consider ownership/cancellation when coroutines are involved.
Score each criterion 0–2: correct behavior, tests that detect the defect, explained trade-off, Kotlin clarity and error handling. Passing stdin/stdout tests alone does not establish design quality; review the structure too.
Patterns → · Refactoring →The Kotlin learning path
A guided route from beginner to advanced across every Kotlin course: begin with the language tour, go deep with the Deep Dive, sharpen your craft with Patterns & Refactoring, and finish with reactive systems. Follow the recommended order — or jump to what you need.