Define the Concept

What is a cart, conceptually? A temporary collection of products the user intends to purchase. Identity, ownership, lifetime — understood before anything is represented in code.

Define the Concept
▶ lab

A cart is "a temporary collection of products the user intends to purchase, held between browsing and checkout." One sentence, no code — and every word in it is a decision: temporary, collection, products, intends, between browsing and checkout. The state, operations and rules are read off that sentence.

Q · You know you need a cart. Before any state, operation or class — what is a cart, and how do you know when the sentence is good enough to build from?
Does It Have Identity?

Two carts with the same items are two carts, because each belongs to someone and will become a different order. That is identity, and it is the first question a definition has to answer — because it decides whether the thing needs an id, whether equality means "same contents" or "same thing", and what happens when two of them look alike.

Q · Two carts hold exactly the same items. Are they the same cart? And what does your answer decide about the code?
Who Owns It, and How Long Does It Exist?

A cart belongs to a shopper and lives from the first add until checkout or abandonment. Whether it survives a reload, a closed browser or a login is not part of the meaning — each is a question whose answer is a persistence decision made later. The definition's job is to ask the questions, name the default, and say which version answers each.

Q · Who does the cart belong to, and when does it stop existing — and which of those answers are part of the concept, and which are decisions you get to defer?
Nouns to Data, Verbs to Behaviour

"A customer adds products to a cart." Nouns: Customer, Product, Cart — candidates for data. Verb: add — a candidate for behaviour. It is a heuristic for finding candidates, not a law for finding classes: "total" is a noun and turns out to be a computation, and "quantity" is nowhere in the sentence and turns out to be state.

Q · You have the sentence. How do you get from its words to a first list of data and behaviour — and where does the noun/verb trick mislead you?
Meaning Before Representation
▶ lab

Do not start with classes or interfaces. A `class Cart` typed on the first morning fixes the representation before the data has been discovered — a stored total, a copied product name, an item type nobody challenged. Discover what the cart must remember, what can happen to it and what must stay true; the class, if there is one, is the last thing written and the easiest to change.

Q · Why not just write the class? What does typing `class Cart { items: Item[] }` on the first morning decide, and what would you have found out if you had waited?