Bird
Raised Fist0
LLDsystem_design~25 mins

Class diagrams in LLD - System Design Exercise

Choose your learning style10 modes available
Design: Class Diagram Design
Focus on designing class diagrams for object-oriented systems. Out of scope are dynamic diagrams like sequence or activity diagrams.
Functional Requirements
FR1: Represent the static structure of a system using classes
FR2: Show class attributes and methods
FR3: Illustrate relationships between classes such as inheritance, association, aggregation, and composition
FR4: Support visibility indicators (public, private, protected)
FR5: Allow modeling of interfaces and abstract classes
Non-Functional Requirements
NFR1: Diagram must be clear and easy to understand for beginners
NFR2: Must follow UML standard notation
NFR3: Should be scalable to model small to medium systems
NFR4: Must be technology-agnostic
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Classes with attributes and methods
Relationships: inheritance, association, aggregation, composition
Visibility markers (+ public, - private, # protected)
Interfaces and abstract classes
Design Patterns
Inheritance for code reuse
Composition to model strong ownership
Aggregation for weak ownership
Interface implementation for polymorphism
Reference Architecture
  +----------------+        +----------------+
  |    Animal      |<-------|    Dog         |
  +----------------+        +----------------+
  | - name: String |        |                |
  | + eat(): void  |        | + bark(): void |
  +----------------+        +----------------+
          ^                          
          |                          
  +----------------+                
  |    Cat         |                
  +----------------+                
  | + meow(): void |                
  +----------------+                

  +----------------+        +----------------+
  |    Person      |<>------|    Car         |
  +----------------+        +----------------+
  | - name: String |        | - model: String |
  | + drive(): void|        +----------------+
  +----------------+
Components
Class
UML notation
Represents an entity with attributes and methods
Inheritance
UML arrow with hollow triangle
Shows 'is-a' relationship for code reuse
Association
UML solid line
Represents a relationship between classes
Aggregation
UML line with hollow diamond
Represents a whole-part relationship with weak ownership
Composition
UML line with filled diamond
Represents a whole-part relationship with strong ownership
Visibility
Symbols +, -, #
Indicates access level of attributes and methods
Interface
UML interface notation
Defines a contract for classes to implement
Request Flow
1. Identify key entities in the system and define them as classes
2. Add relevant attributes and methods to each class
3. Determine relationships between classes and represent them using appropriate UML connectors
4. Mark visibility for each attribute and method
5. Use inheritance to model shared behavior
6. Use interfaces to define common contracts
7. Review diagram for clarity and completeness
Database Schema
Not applicable for class diagrams as they model system structure, not data storage.
Scaling Discussion
Bottlenecks
Diagram becomes cluttered and hard to read with many classes
Complex relationships can confuse beginners
Maintaining diagram consistency as system evolves
Solutions
Use packages or modules to group related classes
Limit diagram scope to key classes for clarity
Use layering to separate concerns
Employ tools that support zoom and filtering
Regularly update diagrams to reflect system changes
Interview Tips
Time: Spend 10 minutes understanding the system entities, 15 minutes drawing classes and relationships, 10 minutes reviewing and explaining the diagram, 10 minutes answering questions.
Explain how classes represent real-world entities
Describe relationships and why chosen (inheritance, association, etc.)
Discuss visibility and encapsulation
Mention use of interfaces and abstract classes for flexibility
Highlight clarity and maintainability of the diagram

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