Bird
Raised Fist0
LLDsystem_design~20 mins

Class diagrams in LLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Class Diagram Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Identify the correct relationship type in a class diagram

In a class diagram, which relationship best represents a 'Car' class having an 'Engine' class as a part of it, where the engine cannot exist without the car?

AComposition
BAssociation
CAggregation
DInheritance
Attempts:
2 left
💡 Hint

Think about whether the 'Engine' can exist independently of the 'Car'.

❓ Architecture
intermediate
2:00remaining
Determine the correct multiplicity in a class diagram

A 'Library' class contains multiple 'Book' objects. Which multiplicity notation correctly represents this in a class diagram?

ALibrary 1 ----- * Book
BLibrary 1 ----- 1 Book
CLibrary * ----- 1 Book
DLibrary 0..1 ----- 0..1 Book
Attempts:
2 left
💡 Hint

Consider how many books a library can have.

❓ scaling
advanced
3:00remaining
Choose the best class diagram design for a scalable user management system

You need to design a user management system that supports different user roles with specific permissions. Which class diagram design is best for scalability?

ASeparate classes for each user role inheriting from User class with hardcoded permissions
BUser class with a single string attribute listing all permissions
CUser class with Role class and Permission class linked via associations
DSingle User class with many boolean attributes for each permission
Attempts:
2 left
💡 Hint

Think about flexibility and ease of adding new roles or permissions.

❓ tradeoff
advanced
3:00remaining
Tradeoff between inheritance and composition in class diagrams

Which statement best describes a tradeoff when choosing inheritance over composition in class diagrams?

AInheritance offers more flexibility to change behavior at runtime than composition
BComposition leads to tighter coupling between classes than inheritance
CComposition requires more code duplication than inheritance
DInheritance can cause rigid hierarchies making future changes harder compared to composition
Attempts:
2 left
💡 Hint

Consider how easy it is to modify or extend behavior later.

❓ estimation
expert
4:00remaining
Estimate the number of classes in a class diagram for an online shopping system

For an online shopping system with features: user accounts, product catalog, shopping cart, order processing, payment, and reviews, estimate the minimum number of distinct classes needed in a well-designed class diagram.

AAround 5 classes
BAround 10 classes
CAround 20 classes
DMore than 30 classes
Attempts:
2 left
💡 Hint

Think about main entities and supporting classes for each feature.

Practice

(1/5)
1. What does a class diagram primarily represent in system design?
easy
A. The structure of classes and their relationships
B. The flow of data between servers
C. The user interface layout
D. The sequence of method calls

Solution

  1. Step 1: Understand the purpose of class diagrams

    Class diagrams show the static structure of a system by representing classes and their relationships.
  2. Step 2: Differentiate from other diagrams

    Flow of data, UI layout, and method sequences are shown in other diagram types like sequence or activity diagrams.
  3. Final Answer:

    The structure of classes and their relationships -> Option A
  4. Quick Check:

    Class diagram = structure and relationships [OK]
Hint: Class diagrams show classes and links, not flow or UI [OK]
Common Mistakes:
  • Confusing class diagrams with sequence diagrams
  • Thinking class diagrams show UI design
  • Assuming class diagrams show runtime behavior
2. Which of the following is the correct way to represent inheritance in a class diagram?
easy
A. A dashed line with a hollow circle pointing to the child class
B. A dashed line with an open arrow pointing to the child class
C. A solid line with a filled diamond pointing to the parent class
D. A solid line with a hollow triangle arrow pointing to the parent class

Solution

  1. Step 1: Recall UML notation for inheritance

    Inheritance is shown by a solid line with a hollow triangle arrow pointing to the parent class.
  2. Step 2: Identify incorrect options

    Filled diamonds represent composition, dashed lines with open arrows represent dependencies, and hollow circles are not standard UML symbols.
  3. Final Answer:

    A solid line with a hollow triangle arrow pointing to the parent class -> Option D
  4. Quick Check:

    Inheritance = solid line + hollow triangle [OK]
Hint: Inheritance uses solid line + hollow triangle arrow [OK]
Common Mistakes:
  • Mixing composition and inheritance symbols
  • Using dashed lines for inheritance
  • Pointing arrow to child instead of parent
3. Given this class diagram snippet:
Class A - attr1: int + method1()
What does the '-' before attr1 and '+' before method1() mean?
medium
A. '-' means protected attribute; '+' means private method
B. '-' means private attribute; '+' means public method
C. '-' means public attribute; '+' means protected method
D. '-' means static attribute; '+' means abstract method

Solution

  1. Step 1: Understand UML visibility symbols

    In UML, '-' means private visibility, '+' means public visibility.
  2. Step 2: Apply to attributes and methods

    So, attr1 is private attribute, method1() is public method.
  3. Final Answer:

    '-' means private attribute; '+' means public method -> Option B
  4. Quick Check:

    Visibility: '-' private, '+' public [OK]
Hint: '-' = private, '+' = public in UML [OK]
Common Mistakes:
  • Confusing visibility symbols with data types
  • Assuming '-' means protected
  • Mixing static/abstract with visibility
4. Identify the error in this class diagram description:
Class Car - engine: Engine - wheels: List<Wheel> -- engine "1" --- "4" wheels
What is wrong with the association notation?
medium
A. The association should use a hollow diamond for aggregation
B. The multiplicity numbers are reversed; wheels should be "4" and engine "1"
C. The association line uses double dashes instead of a single solid line
D. The class names should be connected with a dashed line

Solution

  1. Step 1: Check association line style

    Associations use a single solid line, not double dashes.
  2. Step 2: Verify multiplicity and line type

    Multiplicity "1" to "4" is correct; aggregation uses hollow diamond but not required here.
  3. Final Answer:

    The association line uses double dashes instead of a single solid line -> Option C
  4. Quick Check:

    Association = single solid line [OK]
Hint: Association lines are single solid lines, not double dashes [OK]
Common Mistakes:
  • Using double dashes for associations
  • Confusing aggregation with association
  • Reversing multiplicity numbers
5. You need to design a class diagram for a library system where a Library has many Book objects, and each Book can have multiple Authors. Which of the following best represents this relationship?
hard
A. Library "1" --- "*" Book; Book "*" --- "*" Author with an association class for author details
B. Library "*" --- "1" Book; Book "1" --- "*" Author with inheritance
C. Library "1" --- "1" Book; Book "1" --- "1" Author with composition
D. Library "*" --- "*" Book; Book "*" --- "1" Author with aggregation

Solution

  1. Step 1: Analyze multiplicity between Library and Book

    A library has many books, so multiplicity is "1" to "*".
  2. Step 2: Analyze multiplicity between Book and Author

    A book can have multiple authors, and authors can write multiple books, so "*" to "*" is correct, often modeled with an association class for author details.
  3. Step 3: Check other options for correctness

    Other options have incorrect multiplicities or wrong relationships like inheritance or composition.
  4. Final Answer:

    Library "1" --- "*" Book; Book "*" --- "*" Author with an association class for author details -> Option A
  5. Quick Check:

    Library to Book = 1 to many; Book to Author = many to many [OK]
Hint: Many-to-many needs association class; library has many books [OK]
Common Mistakes:
  • Using inheritance instead of association
  • Incorrect multiplicity numbers
  • Confusing composition with aggregation
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