AlgoViz

SOLID in one page

medium 45 min

Five principles for classes that can be changed without fear: single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion.

Watch lesson5:16

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Signals

Which letter does the interviewer want?

You hearLetterSay
This class is hard to testS, DWhat is outside goes behind a port, the rules move out
We will add more types laterOContract now, because the kinds are named. Otherwise at the second one
Is a penguin a bird here?LWhat do callers of Bird rely on?
Not every device can scanITwo interfaces, one class may have both
We may change the providerDThe port is ours, in our words
Now extend it, ten minutes leftAllShow which lines stay
Is this not over-engineered?NoneName what you would remove

Saying it in the room

  1. Interviewer

    Your NotificationService creates an SmtpClient. Any concerns?

  2. You

    Two. I cannot test the rules without a server, and a second channel would be a branch. I hand in a list of Sender.

  3. Interviewer

    What exactly does Sender promise?

  4. You

    It delivers the whole text or returns a receipt with a reason. It does not raise for a failed delivery, so one bad channel cannot stop the others.

  5. Interviewer

    A push channel allows only 100 characters.

  6. You

    Then it cannot be a Sender of whole texts. It gets its own small contract for a title and a link. Otherwise the service needs a special case, and that is how the branch comes back.

Design a parking fee: hourly now, maybe daily later. How much SOLID do you show?

BreaksAll five from the start
How
Five interfaces, a factory, a registry.
Limit
Twenty minutes gone, no working fee.
Choose when
Never in a timed round.
WorksOne method with the hourly rate
How
Simple and correct.
Limit
The extension question edits it. Acceptable if you say where.
Choose when
Very short rounds.
StrongA fee function handed in, one kind
How
lot = ParkingLot(fee=hourly). No hierarchy. At the extension, a second function and one changed line.
Limit
You must explain why there is no interface yet.
Choose when
Nearly always: the cheapest seam that the next wish needs.