UML Class Diagram
UML (Unified Modeling Language) Class Diagrams are used for Conceptual Data Modeling — capturing the domain’s entities, attributes, and relationships at a high level before translating to a logical Entity-Relationship Diagram (ERD). UML is often preferred for conceptual modeling because it is more expressive and cleaner than ERD notation for representing type hierarchies and complex relationships.
Class Structure
A class has three compartments:
┌──────────────────┐
│ ClassName │ ← Name
├──────────────────┤
│ - attribute1: Type│ ← Attributes
│ - attribute2: Type│
├──────────────────┤
│ + method(): Type │ ← Operations (optional for DB modeling)
└──────────────────┘
Visibility markers: + public, - private, # protected, ~ package.
Relationship Types
Association
A domain-level connection between classes. Bidirectional by default.
Student ────── Course
enrolls
Aggregation (◇──)
A whole-part relationship where parts can exist independently of the whole. Hollow diamond on the whole side.
Example: Department ◇── Employee (employees exist without the department)
Composition (◆──)
A stronger whole-part relationship where parts cannot exist independently. Filled diamond.
Example: Order ◆── OrderItem (order items don’t exist without the order)
Generalization (△──)
Class hierarchy / inheritance. Hollow triangle arrowhead.
Example: Person △── Student, Person △── Employee
Multiplicity
Annotations on relationship endpoints defining how many instances participate:
| Notation | Meaning |
|---|---|
1 | Exactly one |
0..1 | Zero or one (optional) |
* or 0..* | Zero or more |
1..* | One or more (at least one) |
n..m | Between n and m |
Read from one class toward the other: “One instance of Class A is associated with [multiplicity] instances of Class B.”
Aggregation and Composition Patterns
The source material identifies several recurring patterns for recognizing aggregation and composition in a domain. Both are anti-symmetric and transitive (if A contains B and B contains C, then A contains C).
| Pattern | Type | Example | Key Phrase |
|---|---|---|---|
| Assembly-Parts | Aggregation | Car ◇── Engine, Wheel | ”is assembled from” |
| Container-Content | Aggregation | WebPage ◇── AdFrame | ”holds”, “displays” |
| Organization-Member | Aggregation | Team ◇── Player | ”consists of members” |
| Material-Object | Composition | Paper ◆── WoodFiber, Cotton | ”is made from” |
| Portion-Ingredient | Composition | Pie ◆── Slice (homomeric) | “portion of” |
| Place-Area | Composition | Country ◆── State ◆── City | ”is located in” |
| Collection-Members | Composition | WeeklyTimesheet ◆── DailyTimesheet | ordered, permanent parts |
When in doubt, model the relationship as an association — it can always be refined into aggregation or composition when additional constraints are discovered.
Mapping to ERD
| UML | ERD |
|---|---|
| Class | Entity |
| Attribute | Attribute |
| Association | Relationship with Foreign Key |
| Aggregation | Relationship (parts optional) |
| Composition | Relationship with CASCADE delete |
| Generalization | Collapsed via discriminator column, separate tables, or shared PK |
| Many-to-Many | Junction Table |