Command Palette

Search for a command to run...

PHASE 3Intermediate ~6 min· topic 3 of 7

Topic 3.3

Responsibility Assignment

In one line

The single most important LLD skill: deciding which class owns which behavior — and keeping responsibilities from bleeding across classes.

0/7 · 0%

Think of it like this

A restaurant. The chef cooks, the waiter serves, the cashier bills. If the waiter starts cooking and billing too, everything slows down and mistakes pile up. Every class should have one clear job.

Key ideas

  1. 01

    Ask: 'who knows X best?' — pricing lives with the pricing policy, not the parking lot.

  2. 02

    Ask: 'who will change when X changes?' — that class owns X (SRP by change-reason).

  3. 03

    Split behavior from data orchestration: domain entity computes, service class orchestrates.

  4. 04

    Testability signals: if a behavior needs 5 collaborators, it's probably in the wrong class.

  5. 05

    Tell-don't-ask: give an object its data and let it behave, instead of pulling state out and deciding elsewhere.

  6. 06

    Interview habit: narrate 'ParkingSpot owns its occupied state; ParkingLot assigns spots; TicketOffice prices'.

Java / Spring map

  • →

    Spring layering: Controller (transport) → Service (orchestration) → Domain (behavior) → Repository (persistence).

Explain without notes

01

Who owns fee calculation when pricing depends on spot type AND vehicle type — and why?

Practice

01

Refactor an anemic ParkingLot with all logic in one class into entities + a service.

Trade-offs

  • ↔

    Over-moved logic = anemic; under-moved = God class. This line is the craft.

Completion checklist

  • I can assign each use case to an owning class and defend it in one sentence.

Back to phase