1.4.9 Parameters in UML Class Diagrams

A Class Diagram Can Show What Input a Method Accepts

You already know that a class diagram can list methods.

Earlier, a parameterless method could appear as:

DisplayName() : void

A method that accepts a parameter can include that parameter in the method notation.

For example:

SetJerseyNumber(number : int) : void
Read the Parameter from Name to Type

Inside the parentheses:

number : int

means:

  • parameter name: number ;
  • parameter type: int .

Read the entire method entry as:

Connect UML to the C# Method Definition

UML:

SetJerseyNumber(number : int) : void

C#:

public void SetJerseyNumber(int number)
{
    this.jerseyNumber = number;
}

The notation order differs slightly.

The parameter meaning is the same.

Boolean Parameters Can Be Shown the Same Way

UML:

SetAvailability(available : bool) : void

C#:

public void SetAvailability(bool available)
{
    this.isAvailable = available;
}

The class diagram describes the method's structure.

The C# supplies the executable implementation.

Class Diagrams Show Parameters, Not Specific Arguments

A class diagram describes the method generally:

SetJerseyNumber(number : int)

It does not normally show one specific call such as:

SetJerseyNumber(7)

That specific interaction belongs naturally in a sequence diagram.

Compare the Two UML Views
Class diagram
SetJerseyNumber(number : int) : void

Question answered:

Sequence diagram
SetJerseyNumber(7)

Question answered:

This mirrors the parameter/argument distinction in C#.

Keep the Current Scope to One Parameter

Later Learning Activities add methods with multiple parameters.

For now, keep the notation simple:

MethodName(parameterName : Type) : void

The current goal is to connect:

method parameter in C#
        ↕
parameter notation in UML class diagram
        ↕
argument shown in sequence diagram