Visual Paradigm Desktop VP Online

Demystifying UML 2.0: The Crucial Difference Between Multiplicity and Cardinality

Introduction

In the realm of software engineering and object-oriented design, the Unified Modeling Language (UML 2.0) serves as the standard visual vocabulary for architects and developers. When modeling relationships between classes and objects, practitioners frequently use the terms multiplicity and cardinality synonymously. However, this is formally incorrect.

While both terms deal with the "number of instances" in a relationship, they represent fundamentally different concepts that apply to different phases of the software lifecycle. Confusing the two can lead to miscommunications between design-time architecture and runtime system behavior. This guide will clarify the formal definitions, highlight the key differences, and provide visual examples to solidify your understanding of these critical UML concepts.

UML Modeling: Multiplicity vs Cardinality by visual Paradigm


Key Concepts

To master UML 2.0 relationships, it is essential to separate the rules of the design from the reality of the runtime.

1. Multiplicity (The Blueprint)

Multiplicity is the definition of an interval of non-negative integers that specifies the allowable number of instances that can be associated with another element.

  • It represents a range or set of possible values.

  • It is defined at the Class Model level (design time).

  • It acts as a constraint or rule, dictating how many instances are allowed to exist.

2. Cardinality (The Reality)

Cardinality refers to a concrete, specific number of elements currently in a set.

  • It represents the actual count of instances observed.

  • It is evaluated at the Object Model level (runtime).

  • It describes how many instances actually exist in a specific, real-world case.

Summary of Differences

Feature Multiplicity Cardinality
Nature An interval or range (e.g., 0..*1..5). A single, specific integer (e.g., 3).
Model Level Defined in the Class Model (design time). Observed in the Object Model (runtime).
Purpose Sets the rules for how many instances are allowed. Describes how many instances actually exist in a specific case.

Illustrative Example: Customers and Bookings

To ground these concepts, consider a system managing a Customer and their Bookings.

  • Multiplicity (Design Time): In our UML Class Diagram, we define the relationship between the Customer class and the Booking class. We set the multiplicity to 0..* (zero to many). This is a business rule stating that a customer is allowed to have any number of bookings, including having absolutely none.

  • Cardinality (Runtime): Fast forward to the system running in production. We query the database for a specific customer instance (e.g., Customer_101). We observe that this specific customer currently has exactly 3 booking objects associated with them. In this specific runtime scenario, the cardinality of the set is 3.


Multiplicity Notation

In UML 2.0, multiplicities are written on the ends of association lines in class diagrams. They are expressed as a single number or a value range.

Standard Notations

  • 1: Exactly one (shortcut for 1..1).

  • 0..1: Zero or one (optional).

  • *: Zero to an arbitrary number (shortcut for 0..*).

  • 1..*: One to an arbitrary number (one or more).

  • 1..5: A minimum of one and a maximum of five.

Rules for Multiplicity

  1. Logical Bounds: Multiplicities must always have a lower value that is equal to or smaller than the upper value (e.g., 1..5 is valid; 5..1 is invalid).

  2. Valid Values: All values must be non-negative integers (e.g., 012...), ensuring the bounds make logical sense for counting instances.


Diagram Examples

Below are PlantUML code examples demonstrating how multiplicity and cardinality are represented visually in UML 2.0.

1. Class Diagram: Illustrating Multiplicity

This diagram shows the design-time rules. The Customer class is allowed to have between zero and an infinite number of Booking instances.

@startuml
skinparam classAttributeIconSize 0
skinparam monochrome true

class Customer {
  + customerId: String
  + name: String
}

class Booking {
  + bookingId: String
  + date: Date
  + amount: Decimal
}

' Multiplicity is defined on the association line
Customer "1" -- "0..*" Booking : has >

note right of Customer
  **Multiplicity**
  Defines the allowed range
  of instances at design time.
  Rule: A customer can have 
  0 to many bookings.
end note
@enduml

2. Object Diagram: Illustrating Cardinality

This diagram shows a snapshot of the system at runtime. We are looking at specific instances (objects) rather than abstract classes. Here, the cardinality is exactly 3.

@startuml
skinparam monochrome true

' Define specific object instances
object "cust_01: Customer" as C1 {
  name = "Alice Smith"
}

object "book_A: Booking" as B1 {
  date = "2026-07-15"
}

object "book_B: Booking" as B2 {
  date = "2026-08-02"
}

object "book_C: Booking" as B3 {
  date = "2026-09-10"
}

' Link the specific objects together
C1 -- B1
C1 -- B2
C1 -- B3

note bottom of C1
  **Cardinality**
  The actual count of instances
  at runtime is exactly 3.
  (Conforms to the 0..* multiplicity rule)
end note
@enduml

Conclusion

While the terms multiplicity and cardinality are often used interchangeably in casual conversation, maintaining the formal distinction is vital for precise software modeling.

Multiplicity is your architectural blueprint; it lives in the class model at design time and establishes the boundaries and rules for your system's relationships. Cardinality, on the other hand, is the physical building; it lives in the object model at runtime and represents the concrete, observable reality of your data.

By understanding and applying these concepts correctly, software architects and developers can create more accurate UML diagrams, write better validation logic, and ensure that the runtime behavior of their applications perfectly aligns with their initial design specifications.

Turn every software project into a successful one.

We use cookies to offer you a better experience. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

OK