Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

UML Class Diagrams

Master UML notation and syntax for visualizing class structures.

UML (Unified Modeling Language) Class Diagrams are the foundation of object-oriented design. They help you visualize the structure of your system, understand relationships between classes, and communicate your design effectively.

A Class Diagram shows:

  • Design - Think through your system structure before coding
  • Communication - Visual representation is clearer than text
  • Documentation - Living documentation of your system
  • Interviews - Essential for LLD (Low-Level Design) interviews
  • Refactoring - Understand existing codebases better

A class in UML has three compartments:

  1. Name - The class name
  2. Attributes - Variables/properties (with visibility: + public, - private, # protected)
  3. Methods - Functions/operations
user_example.py
class User:
def __init__(self, username: str, email: str):
self.username = username # Public attribute
self._email = email # Protected attribute
self.__password = None # Private attribute
def login(self): # Public method
pass
def _validate(self): # Protected method
pass
Diagram

UML uses symbols to indicate visibility:

  • + Public - Accessible from anywhere
  • - Private - Only accessible within the class
  • # Protected - Accessible within class and subclasses
  • ~ Package - Accessible within the same package (Java)
Diagram

Multiplicity shows how many instances participate in a relationship:

  • 1 - Exactly one
  • 0..1 - Zero or one (optional)
  • 1..* or 1..n - One or more
  • 0..* or 0..n - Zero or more
  • * or n - Many (zero or more)
  • m..n - Between m and n
Diagram

For detailed explanations of each relationship type, see the Class Relationships section.

RelationshipUML SymbolDescription
InheritanceSolid line with hollow triangle”Is-a” relationship
AssociationSolid line with arrow”Uses-a” or “Knows-a”
AggregationSolid line with hollow diamond”Has-a” (weak ownership)
CompositionSolid line with filled diamond”Has-a” (strong ownership)
DependencyDashed arrow”Uses temporarily”
Diagram

When reading a UML class diagram:

  1. Start with classes - Identify all classes and their names
  2. Check attributes - Understand what data each class holds
  3. Review methods - See what operations each class can perform
  4. Analyze relationships - Understand how classes relate to each other
  5. Check multiplicity - See how many instances are involved
  6. Note visibility - Understand access levels

  1. Keep it simple - Don’t overcomplicate diagrams
  2. Use consistent notation - Follow UML standards
  3. Group related classes - Organize logically
  4. Show only essential details - Hide implementation details
  5. Use meaningful names - Clear, descriptive class and method names
  6. Document relationships - Add labels to clarify relationships

Complete Example: Simple E-Commerce System

Section titled “Complete Example: Simple E-Commerce System”
Diagram

  • Learn about Class Relationships - Detailed explanations of all relationship types
  • Practice drawing UML diagrams for your own projects
  • Use UML diagrams in LLD interviews to communicate your design
  • Explore advanced UML features like interfaces, abstract classes, and packages

Remember: UML diagrams are a tool for communication and design thinking. Focus on clarity and correctness rather than perfect notation!