SOLID in one page
medium 45 minFive 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 hear | Letter | Say |
|---|---|---|
| This class is hard to test | S, D | What is outside goes behind a port, the rules move out |
| We will add more types later | O | Contract now, because the kinds are named. Otherwise at the second one |
| Is a penguin a bird here? | L | What do callers of Bird rely on? |
| Not every device can scan | I | Two interfaces, one class may have both |
| We may change the provider | D | The port is ours, in our words |
| Now extend it, ten minutes left | All | Show which lines stay |
| Is this not over-engineered? | None | Name what you would remove |
Saying it in the room
Interviewer
Your
NotificationServicecreates anSmtpClient. Any concerns?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.Interviewer
What exactly does
Senderpromise?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.
Interviewer
A push channel allows only 100 characters.
You
Then it cannot be a
Senderof 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.