Finding entities and owners 00:00:00 Make a prediction You will distinguish an entity with identity from a value, then assign a fact to the object that can keep it authoritative. A library buys a second copy of the same novel. If availability is a single flag on the title, what happens when just one copy is borrowed? The flag must say available or unavailable for both, so it cannot describe the real situation. The title identifies a work, a barcode identifies a copy, and a loan records who currently holds that copy. 00:00:33 Casting a play A play has a character written in a script, an actor who performs it and a performance on a given night. Replacing tonight's actor does not rewrite the script or replace the actor in every other performance. The script is the shared description. The actor has identity. The performance links the two at a time. Ask which facts must stay true when that link changes; those facts often reveal the boundaries between entities. An entity is a thing that your program follows over time. It has an identity: a dog that gets a new name is still the same dog. A value has no identity: two slots from 9:00 to 9:30 on the same day are simply equal, and you may swap one for the other. Too few classes give one large manager that knows everything. Too many give a crowd of boxes with one number each. Both are hard to change, and both cost you the round: the first has no design to discuss, the second has no time left for methods. 00:01:39 Separate a title from its copies Two copies of the same novel have one title but different barcodes. Storing one availability flag on the title loses that distinction. Give each copy an identity of its own. A loan points to the exact copy and the member who borrowed it. Returning one barcode closes its loan. The other copy can remain checked out without inventing a second title. Put the two books next to each other. Checking out A makes A unavailable while B stays on the shelf. Now change a spelling error in their shared title. Both display names can change together without changing either copy's barcode. Those tests separate descriptive facts from object identity. 00:02:21 Choose a value object A fare of ten dollars and a second fare of ten dollars are interchangeable when their currencies match. Represent money by amount and currency. A booking with the same fare still needs its own identifier because canceling one booking must leave the other intact. Compare two ten-dollar fares. If one is mistakenly represented as ten euros, equality must fail even though both numbers say ten. Bookings are different: two bookings with an identical fare can be canceled independently. Their identities tell you which contract was canceled. Giving each number an identifier produces many entities with no independent history. Trace cancellation or replacement to see whether identity matters. A value such as ten dollars in the same currency can be replaced by an equal value; a particular customer's booking cannot. Django. A many-to-many relation can have an intermediate model, named with through. It holds extra fields of the link, such as the date somebody joined a group. A verb that became a class. Git. A blob stores only contents. The file name is in the tree that lists it. The name belongs to the place and not to the contents. 00:03:39 Try an interview follow-up Why should each fact have one owner? Because two copies drift apart on the path that somebody forgets, usually cancel or failure. With one owner the rule has one place, one lock and one test. A courier corrects a customer's address while a package is in transit. Should the shipment change? Give the parcel an identity that survives edits. Let the shipment store the address agreed at dispatch. A later address correction now raises an explicit reroute decision. Trace it to see why a customer and a shipment own different facts. 00:04:18 What to take with you Underline the nouns and audition each one: does it have an identity that is followed, a rule to guard, or facts that travel together? If not, it is a value, a field, an enum, a caller or nothing. Then give every fact and every rule one owner. The owner of a rule is the object that can see everything the rule needs. A verb with facts of its own becomes a class, such as a walk or a ticket. Say the rejections aloud.