Shallow or deep?
transcript
You copied an object. One line, and it worked. Did you copy what it holds? That's the question.
A shallow copy makes a second cart object. Both carts point at one list. So there is only one cola to change, whichever cart you use.
A deep copy gives the reorder its own list, not a shared one. And its own copy of every item. The past cart keeps its own cola. Nothing is shared, so nothing leaks.
The usual one liners are shallow. Python's copy dot copy, Java's clone, JavaScript's spread. The deep tools: deepcopy, a copy constructor, and structuredClone. That one returns plain data, without methods. In C plus plus, it's the members. Values copy deep. Pointers copy shallow.
But deep has a limit. The cart owns its items, so the copy gets its own. It only uses the app's price list, so the copy shares it. A plain deepcopy would duplicate that too.
Copy what the object owns. Share what it only uses.
Full breakdown in the lecture.