Search code examples
c#umlsequence-diagram

How to represent c# setter in UML sequence diagram?


I will like to set values in a property Scores. How do I draw this in UML sequence diagram? May I clarify if the diagram drawn below is correct?

Code (C#):

From file: Test.cs

public class Test<T>
{
    public IEnumerable<T> Scores { get; set; }
}

From file: TestScore.cs

public class TestScore
{
    List<int> numList = new List<int>() { 1, 2, 3, 4, 5 };
    Test<int> test = new Test<int>();
    test.Scores = numList;
}

UML Sequence Diagram:

Sequence diagram


Solution

  • 1. Is the diagram correct ?

    No, this diagram is not correct. The following initialization in class TestScore:

    test.Scores = numList;
    

    would be a set(numList) message that :TestScore sends to test, because :TestScore invokes the setter of test.

    Since in fact it is the setter of test.Scores that is in reality invoked, you could even consider setScores(numList) to avoid any ambiguity if the class Test would evolve to expose other setters.

    2. Is the diagram a good idea ?

    This diagram seems to be very detailed. Maybe too detailed. The sequence diagram is not intended to be graphical programming, but to document a (complex?) interaction scenario between classes.

    The purpose is to facilitate understanding of an implementation or a design involving object interactions. Whenever the code is easier to understand than the graph, you should question yourself if you’re not overengineering the problem, and also think about the effort required in future to update the graph whenever the code evolves. You alone can judge if it’s worth the effort.