0/0
UML & Documentation

Introduction to UML Class Diagrams

Learn to read and write UML class diagrams β€” the most widely used UML diagram type. Understand the anatomy of a class box: its three compartments, how to describe attributes, constructors, methods, and the four visibility markers that control access.

Explore Topics

πŸ“‹
UML Class Diagram Overview
The static blueprint of your object-oriented system
πŸ—οΈ Class Box Builder β€” Explore UML Notation
Student
-name : String
-gpa : double = 0.0
#id : int
+<<create>> Student()
+<<create>> Student(name: String, id: int)
+getName() : String
+setGpa(g: double) : void
+ public- private# protected~ packageunderline = staticitalic = abstract
πŸ“‹
UML Class Diagram Overview
The static blueprint of your object-oriented system

A UML class diagram is a structural diagram that shows the static view of an application. It describes the types of objects in a system and the structure of each class β€” its name, attributes, and operations. Class diagrams do not show runtime behavior; they capture the design-time structure. Every class is represented as a rectangular box divided into three horizontal compartments: the top for the class name, the middle for attributes (data), and the bottom for operations (behavior). Class diagrams are the most commonly used UML diagram and serve as the foundation for code generation, design reviews, and team communication.

Key Ideas
  • A class diagram shows the static structure β€” classes, attributes, and operations
  • It does NOT show runtime behavior (use Sequence or Activity diagrams for that)
  • Most commonly used UML diagram β€” the foundation for many other diagrams
  • Every class is a rectangular box with three compartments
  • Top compartment: class name β€” Middle: attributes β€” Bottom: operations
  • Used for analysis (understanding the domain) and design (planning the code)
  • Supports forward engineering (diagram β†’ code) and reverse engineering (code β†’ diagram)
Strengths
  • ✦Provides a bird's-eye view of system structure at a glance
  • ✦Language-agnostic β€” same notation works for Java, C#, Python, etc.
  • ✦Serves as a communication tool between developers, architects, and stakeholders
  • ✦Foundation for code generation tools and IDE integrations
Weaknesses
  • β–³Cannot express runtime behavior or execution order
  • β–³Can become cluttered for very large systems β€” need to scope diagrams
  • β–³Requires discipline to keep diagrams in sync with evolving code
  • β–³Students often confuse class diagrams with ER diagrams (database-focused)
Used in:Most Java IDEs (IntelliJ IDEA, Eclipse) can generate class diagrams from source code automatically β€” this is reverse engineering. Conversely, tools like Visual Paradigm and Enterprise Architect can generate Java class skeletons from class diagrams β€” forward engineering.
Code Snippets

Quiz

UML Class Diagram Overview Quiz
QUIZ 1/6
What does the middle compartment of a UML class box contain?

Diagrams

Class Box Anatomy β€” A Fully Annotated Student Class
Loading diagram...
Abstract Class vs Interface vs Concrete Class
Loading diagram...

Practice

Place each element into the correct compartment of a UML class box:
EXERCISE 1/4
Student (bold, centered)
- name : String
- gpa : double = 0.0
+ <<create>> Student(name: String)
+ getName() : String
+ setGpa(g: double) : void
# id : int {readOnly}
Top Compartment (Name)
Middle Compartment (Attributes)
Bottom Compartment (Operations)
Complete the UML Class Box Notation
EXERCISE 2/4
Visibility Markers: = public = private = protected ~ = package Attribute format: visibility : Type Abstract class name is shown in Static members are shown with
UML Class Box Myths
EXERCISE 3/4
Constructors go in the middle compartment (attributes section) of a class box.
A forward slash (/) before an attribute name means it is derived (computed from other values).
Static members in UML are shown in bold text.
In UML, omitting the visibility marker means the member is public by default.
The <<interface>> stereotype is used to mark a class that contains only operation signatures.
Abstract methods are shown in italic to indicate they have no implementation.
Match each visibility marker to its access level:
EXERCISE 4/4
+ (plus)
- (minus)
# (hash)
~ (tilde)
Public β€” visible to all
Private β€” visible only within class
Protected β€” class + subclasses
Package β€” same package only

References

πŸ“„

UML Class Diagram Tutorial β€” Visual Paradigm

visual-paradigm.com

article
πŸ“‹

UML Class Notation Reference β€” uml-diagrams.org

uml-diagrams.org

docs
πŸ“š

UML Distilled β€” Martin Fowler (Addison-Wesley)

martinfowler.com

book
πŸ“‹

OMG Unified Modeling Language Specification v2.5.1

omg.org

docs
πŸ“„

Class Diagram Symbols: Notation and Syntax Explained β€” Creately

creately.com

article