Bird
Raised Fist0
LLDsystem_design~20 mins

Relationships (association, aggregation, composition) in LLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Relationships in System Design
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Identify the type of relationship in a library system

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?

AAssociation
BAggregation
CInheritance
DComposition
Attempts:
2 left
💡 Hint

Think about whether the objects can exist independently.

❓ Architecture
intermediate
2:00remaining
Choose the correct relationship for a car and its engine

A Car has an Engine. The engine can exist independently and can be replaced. What is the correct relationship between Car and Engine?

ADependency
BComposition
CAssociation
DAggregation
Attempts:
2 left
💡 Hint

Consider if the engine can exist without the car.

❓ scaling
advanced
3:00remaining
Impact of composition on object lifecycle in a social media app

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?

AIt allows independent scaling of ProfilePicture storage.
BIt simplifies cleanup but requires careful cascading deletes in the database.
CIt requires ProfilePicture to be cached separately for performance.
DIt means ProfilePicture can be shared among multiple UserProfiles.
Attempts:
2 left
💡 Hint

Think about ownership and lifecycle dependency.

❓ tradeoff
advanced
3:00remaining
Choosing between aggregation and composition for a shopping cart system

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?

AAggregation, because items can exist independently and be shared.
BComposition, because items belong exclusively to one cart.
CAssociation, because items and carts have no ownership.
DInheritance, because items are a type of cart element.
Attempts:
2 left
💡 Hint

Consider if items can be shared or must be owned exclusively.

❓ component
expert
4:00remaining
Designing a document editor with embedded images: relationship choice

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?

ADependency, because images are only used temporarily during editing.
BAggregation, because images are stored separately and can exist independently.
CComposition, because EmbeddedImages lifecycle depends on Document.
DAssociation, because images and documents are loosely connected.
Attempts:
2 left
💡 Hint

Think about ownership and lifecycle dependency despite storage separation.

Practice

(1/5)
1. Which relationship describes two objects connected without ownership, where both can exist independently?
easy
A. Inheritance
B. Association
C. Composition
D. Aggregation

Solution

  1. Step 1: Understand relationship types

    Association means objects are linked but do not own each other and can exist separately.
  2. Step 2: Compare with other relationships

    Aggregation and composition imply ownership; inheritance is a different concept.
  3. Final Answer:

    Association -> Option B
  4. Quick Check:

    Association = connected without ownership [OK]
Hint: No ownership means association, not aggregation or composition [OK]
Common Mistakes:
  • Confusing aggregation with association
  • Thinking composition allows independent existence
  • Mixing inheritance with relationships
2. Which of the following correctly shows a composition relationship in UML notation?
easy
A. A solid diamond at the owner end connected to the part
B. A hollow diamond at the owner end connected to the part
C. A plain line with no diamonds between objects
D. A dashed arrow pointing from part to owner

Solution

  1. Step 1: Recall UML notation for composition

    Composition uses a solid diamond at the owner end to show strong ownership.
  2. Step 2: Differentiate from aggregation and association

    Aggregation uses hollow diamond; association uses plain line; dashed arrow is for dependency.
  3. Final Answer:

    A solid diamond at the owner end connected to the part -> Option A
  4. Quick Check:

    Composition = solid diamond [OK]
Hint: Solid diamond means composition, hollow means aggregation [OK]
Common Mistakes:
  • Mixing hollow and solid diamonds
  • Confusing association line with composition
  • Using dashed arrows for composition
3. Consider this code snippet representing relationships:
class Engine:
    pass

class Car:
    def __init__(self):
        self.engine = Engine()
What type of relationship does Car have with Engine?
medium
A. Association
B. Aggregation
C. Inheritance
D. Composition

Solution

  1. Step 1: Analyze ownership in code

    Car creates and owns Engine instance inside its constructor, implying strong ownership.
  2. Step 2: Match with relationship definitions

    Since Engine cannot exist meaningfully without Car here, this is composition.
  3. Final Answer:

    Composition -> Option D
  4. Quick Check:

    Car owns Engine fully = Composition [OK]
Hint: Creating owned object inside means composition [OK]
Common Mistakes:
  • Thinking it's aggregation because of ownership
  • Confusing association with composition
  • Assuming inheritance from code
4. Identify the error in this aggregation example:
class Wheel:
    pass

class Car:
    def __init__(self, wheels):
        self.wheels = wheels

car = Car([Wheel(), Wheel()])
What is wrong with this aggregation?
medium
A. Wheels cannot exist independently in aggregation
B. Car should not hold wheels as a list
C. No error; this is correct aggregation
D. Wheels should be created inside Car for composition

Solution

  1. Step 1: Understand aggregation ownership

    Aggregation means Car owns wheels but wheels can exist independently.
  2. Step 2: Check code for ownership and independence

    Wheels are created outside Car and passed in, so they can exist alone, matching aggregation.
  3. Final Answer:

    No error; this is correct aggregation -> Option C
  4. Quick Check:

    Aggregation allows independent parts [OK]
Hint: Aggregation parts created outside owner, passed in [OK]
Common Mistakes:
  • Thinking wheels must be created inside Car
  • Confusing aggregation with composition
  • Assuming list usage is wrong
5. You are designing a library system where a Library contains many Books. Books can exist outside the library and be moved between libraries. Which relationship best fits this scenario and why?
hard
A. Aggregation, because library owns books but books can exist alone
B. Composition, because books depend fully on the library
C. Association, because library and books are loosely connected
D. Inheritance, because books inherit properties from library

Solution

  1. Step 1: Analyze ownership and existence

    Books can exist independently and move between libraries, so they are not fully owned.
  2. Step 2: Match relationship type

    Aggregation fits because library owns books but books can exist alone and be shared.
  3. Final Answer:

    Aggregation, because library owns books but books can exist alone -> Option A
  4. Quick Check:

    Aggregation = ownership with independent parts [OK]
Hint: If parts can exist alone, use aggregation [OK]
Common Mistakes:
  • Choosing composition thinking books depend fully
  • Selecting association ignoring ownership
  • Confusing inheritance with ownership
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard