In a library system, a Book can be borrowed by many Members, and a Member can borrow many Books. What type of relationship is this?
Think about whether the objects can exist independently.
This is an association because both Book and Member can exist independently and are linked by borrowing.
A Car has an Engine. The engine can exist independently and can be replaced. What is the correct relationship between Car and Engine?
Consider if the engine can exist without the car.
Aggregation is correct because the engine can exist independently and is part of the car but not owned exclusively.
In a social media app, a UserProfile contains ProfilePicture as a part of it. If the UserProfile is deleted, the ProfilePicture is also deleted. What is the impact of this composition relationship on system design when scaling?
Think about ownership and lifecycle dependency.
Composition means the ProfilePicture lifecycle depends on UserProfile, so deleting UserProfile must also delete ProfilePicture, requiring cascading deletes.
In a shopping cart system, a ShoppingCart contains multiple Items. Items can exist without the cart and can be added to multiple carts. Which relationship is best and why?
Consider if items can be shared or must be owned exclusively.
Aggregation fits because items exist independently and can be shared among carts, unlike composition which implies exclusive ownership.
You are designing a document editor where a Document contains multiple EmbeddedImages. EmbeddedImages cannot exist outside the document and are deleted when the document is deleted. However, images can be large and stored separately for performance. Which relationship best models this scenario and why?
Think about ownership and lifecycle dependency despite storage separation.
Composition is correct because EmbeddedImages cannot exist without the Document, even if stored separately, their lifecycle is tied to the Document.