Aggregation vs composition 00:00:00 Make a prediction You will distinguish a shared association from exclusive ownership by asking what survives deletion or transfer. The red team disbands. Must its players disappear from the league as well? No. Their memberships end, but the players keep their identities and can transfer. The team points to people whose lifetime is independent of that roster. 00:00:25 The castle and the tide Two sand castles can use the same wheelbarrow to carry sand. A turret, on the other hand, belongs to one castle in this model. When the tide flattens that castle the wheelbarrow can still roll away. Sharing the wheelbarrow models aggregation. The turret's existence as that castle's part models composition. A field pointing to a part does not, by itself, tell you who owns its lifetime. An object often has other objects. Composition is the strong form: the part belongs to exactly one whole, the whole is responsible for it, and the part is removed with the whole. An order and its lines, a house and its rooms. The question is not academic. It decides who may delete, who may change, whether a part can be shared, what a copy must copy, and what the database does when a row disappears. 00:01:22 Transfer a player between teams A player leaves the red team. Deleting the membership ends the association, while the same player can join the blue team with the same identity. The roster aggregates players; it does not own their existence. Other objects can still refer to the player after the team disbands. Contrast an order and its internal line items. When a draft order is discarded, its privately owned lines have no independent order to belong to. Remove Noor from the red-team roster. Her red membership ceases to exist. Her player record and blue-team eligibility remain. Deleting the shared player during removal would break another team or erase her history. Make the lifetime decision explicit when implementing cascades. 00:02:10 Ask who owns the lifetime A playlist refers to tracks also used by other playlists. Deleting the playlist must leave the music available. A document's internal page-layout records may instead belong exclusively to that document. How disposal and sharing work decides the relationship, even if both designs use a list field. Put the same song in two playlists with different positions. Deleting the first playlist destroys its ordering entry but leaves the song and the second ordering intact. For an internal page layout, removal of the containing document may legitimately delete its layout records. Test both ownership cases. A database cascade that removes shared players when the team row is deleted violates the model even if the diagram looks plausible. Store a separate membership record when you must retain transfer history; give it its own start and end while keeping players independent. In the Qt object model, destroying a parent also destroys its child objects. Another ownership model is the unique pointer in C plus plus: moving the pointer transfers ownership. A shared reference to a song from several playlists makes a very different promise. Test which parts actually survive removal of their container. 00:03:30 Try an interview follow-up How do you move an owned part from one whole to another? Release from the first, add to the second, and put it back if the second refuses. One owner at each moment. With threads, two locks in a fixed order. In a database, one transaction, or a change of the owner's id in one row. A machine body is scrapped, but a separately tracked sensor is moved into a replacement body. Should removing the body delete the sensor record? The sensor has identity and maintenance history beyond its current installation. End the installation relationship and assign the sensor to the new body. An internal calibration layout used only by the old body can have a different lifetime. 00:04:16 What to take with you Composition: one owner, the part ends with the whole. Aggregation: a reference, the part lives on. Filled and hollow diamond, at the whole. Ask four questions: who creates it, who may share it, who may change it, who deletes it. Creation alone does not decide.