AlgoViz

IS-A and HAS-A

easy 40 min

IS-A says that an object is a kind of something and can stand in for it.

Watch lesson4:45

When it comes up

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

Signals

When the choice comes up

You hearThinkSay
Users can become adminsBegins and endsA role that the user has
Premium accounts with insurance and cashbackFeatures combineA list of features, not subclasses
Our queue should reuse ArrayListWants code, not the typeA queue has a list
Pieces on a board move differentlyKinds for life, same questionPiece as a contract. A pawn that is promoted is replaced
A report in PDF, sent by mailTwo independent reasonsA report has a format and a sender

Saying it in the room

  1. Interviewer

    You made ElectricCar a subclass of Car. Why?

  2. You

    Let me test it. It is a car for life, and a garage uses it as a car. But refuel() makes no sense on it, so a promise is broken.

  3. Interviewer

    So?

  4. You

    The car has a drive with topUp(). Petrol and electric are kinds of drive, and a hybrid has two. Car itself promises only what all cars do.