0.3.18 Contrasting UML Object, Activity, and Class Diagrams

Three UML Diagrams Answer Three Different Questions

You have now worked with three UML diagram types:

All three can describe the same soccer system.

They do different jobs.

A useful shortcut is:

Object diagram: What specific things exist right now?

Activity diagram: What happens next?

Class diagram: What kinds of things can the system represent?

Object Diagrams Show Specific Instances

An object diagram focuses on a snapshot.

For example:

Plain text
player1 : Player
-------------------------
name = "Jordan"
jerseyNumber = 7
isAvailable = true

This is one specific Player object.

The diagram may also show relationships to specific objects such as:

Plain text
team1 : Team
match1 : Match

Object diagrams are useful when the important information is:

Activity Diagrams Show Flow

An activity diagram focuses on actions and paths.

For example:

Plain text
Start
  ↓
Read availability
  ↓
Is player available?
  ├─ [yes] → Add player to list
  └─ [no]  → Continue
  ↓
End

This diagram is not primarily about the internal field list for Player.

It is about the process.

Activity diagrams are useful when the important information is:

Class Diagrams Show Types and Structure

A class diagram describes kinds of objects.

For example:

Plain text
Player
--------------------------------
name : string
jerseyNumber : int
isAvailable : bool

This does not describe one specific player.

It says what information Player objects can contain.

Class diagrams are useful when the important information is:

Compare the Same Soccer Idea

Suppose the system needs to represent player availability.

Object-diagram view

Plain text
player1 : Player
-------------------------
isAvailable = true

Question answered:

What is true about this specific object right now?

Class-diagram view

Plain text
Player
-------------------------
isAvailable : bool

Question answered:

What kind of information can Player objects contain?

Activity-diagram view

Plain text
Is player available?
  ├─ [yes] → Add to lineup
  └─ [no]  → Continue

Question answered:

How does availability affect the process?

The concept is related across all three diagrams.

The representation changes because the question changes.

Do Not Force One Diagram to Do Another Diagram's Job

An object diagram should not become a substitute for process flow.

A class diagram should not be filled with one particular player's current values.

An activity diagram should not become a list of every attribute in the system.

Using the wrong representation makes the model harder to interpret.

Choose the diagram based on the problem you are trying to understand.

The Diagrams Can Support One Another

A class diagram can define:

Plain text
Player
-------------------------
isAvailable : bool

An object diagram can show:

Plain text
player1 : Player
-------------------------
isAvailable = true

An activity diagram can use that state in a decision:

Plain text
Is player available?
  ├─ [yes] → Include player
  └─ [no]  → Exclude player

Those models are not duplicates.

They are complementary views.

UML and C# Will Also Connect

The same class attribute:

Plain text
isAvailable : bool

can correspond to a Boolean value in C#.

The object diagram shows the current value.

The activity diagram shows how the value affects flow.

C# provides executable instructions that create the object, store the value, and make the decision.

That creates a useful chain:

Class structure → Object state → Process flow → Program code

Choose by the Question

Use this table as a mental guide:

Question Diagram
Which specific objects exist? Object diagram
What values do those objects currently have? Object diagram
What action happens next? Activity diagram
Which path is followed? Activity diagram
What classes exist? Class diagram
What attributes and types belong to a class? Class diagram
How are kinds of objects structurally related? Class diagram

The strongest diagram is not the one with the most information.

It is the one that answers the current question clearly.