I have the following sequence diagram to add a student to a list of students.
the implementation could be like
List<Student> Students = new List<Student>();
Students.Add(aStudent);
I drew the following sequence diagram for it:
In this diagram Students
is actually the list of students mentioned in the code.
I would like to know is it a correct way to show a list of objects as a object lifeline? I mean as a conceptual and analysis approach and also at syntax.
For example maybe the List<Student>
could be the object of a general class named Storage
which is responsible to store and retrieve a list of objects like a database…
Description of lifeline from UML 2.4.1 standard:
A Lifeline is shown using a symbol that consists of a rectangle forming its “head” followed by a vertical line (which may
be dashed) that represents the lifetime of the participant. Information identifying the lifeline is displayed inside the
rectangle in the following format:<lifelineident> ::= ([<connectable-element-name>[‘[‘ <selector> ‘]’]] [: <class_name>] [decomposition]) | ‘self’ <selector> ::= <expression> <decomposition> ::= ‘ref’ <interactionident> [‘strict’]
So, you should rename Students
to Students : List<Student>
or just :List<Student>
. The part after colon (:
) represents a type (<class_name>
from notation above).
There is no special syntax for representing lists.
EDIT: as for “Student Storage/Adapter”
If List does the job, just use it. It is object-oriented enough as it is. No need to introduce a pattern for the sake of introducing a pattern, and more than so for the sake of writing a busy-sounding class name to a diagram. Keep it simple.
3