AlgoViz

Finding entities and owners

medium 35 min

A spec is full of nouns, and most of them are not classes.

Video lesson · Chapter 1 of 6

Make a prediction

0:00 / 4:50

See it run

Which noun becomes an object, who may change what, and what goes wrong with two owners.

Operations

The audition

Each noun of the spec gets one verdict and one reason.

Step 1 of 8

Dog and volunteer

WhyVerdict
dogfollowed over timeentity
volunteerfollowed over timeentity
walk
time slot
level
phone
leash
nervous dog
(not named)

We tell two of them apart and follow them. Entities.

Step 1: Dog and volunteer

followed over time?      entityguards a rule?           ownerfacts travel together?   valuelink with facts?         class for the linkfixed words?             enumonly calls us?           no classin no sentence?          out of scope
When
First two minutes
You leave with
A short cast list

Say the rejections aloud. They show judgement, boxes do not.

In the real world

The same finding entities and owners doing real jobs. Pick one and step through it.

The noun book is two things, and the verb lend is a third.

Step 1 of 5

A title

MobyTitleauthorMelvilleholds1

People search for a title and reserve a title.

Step 1: A title

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • A box for every noun

    major

    The round is spent on classes with one field and no method.

    Wrong
    class Leash: ...class Phone: ...class Day: ...
    Right
    # leash: in no sentence. phone: calls us. day: a field of Slot
  • Subclasses for one value

    major

    A dog that calms down cannot change its class.

    Wrong
    class NervousDog(Dog): ...
    Right
    dog.needs = Level.EASY
  • A list on both sides

    critical

    Cancel forgets one of them, and a ghost stays.

    Wrong
    dog.walks.append(walk)volunteer.walks.append(walk)
    Right
    rota._walks[walk.id] = walk   # the only place
  • The missing owner

    critical

    A rule about all walks cannot be checked by one dog.

    Wrong
    class Dog:    def book(self, volunteer, slot): ...
    Right
    class WalkRota:    def book(self, dog, volunteer, slot): ...
  • A value that changes

    major

    The walk moves after it was checked, around the owner.

    Wrong
    walk.slot.start = 600
    Right
    rota.cancel(walk.id)rota.book(walk.dog, walk.volunteer, Slot(1, 600, 630))

Interview tips

  • Reject aloud

    • Half a sentence each
    • Say what would bring it back
    • A short cast list is a good one
  • Ask who can see it

    • List what a rule needs
    • Smallest object that sees all
    • None? Add an owner
  • One truth

    • Derive before you store
    • Check cancel and failure
    • Values are frozen
  • Name by content

    • Rota, pool, deck, game
    • Not manager, handler, helper
    • No name means several jobs