How to present static class or function call in Se

2020-06-03 07:56发布

问题:

How is a static class or call to a static function presented in Sequence Diagram? As per my understanding, the lifeline belongs to an instance/object of a class. This article says metaclass stereotype can be used.

回答1:

"In case of doubt, use comments, or stereotypes..."

Sequence Diagram:

.......................................................
....+-------------+...........+-------------------+....
....|  <<class>>  |...........|     <<class>>     |....
....|     Cat     |...........|  FastFoodTerminal |....
....+------+------+...........+---------+---------+....
...........|............................|..............
...........|..........<<static>>........|..............
...........|...........TurnOn().........|..............
...........+--------------------------->+---+..........
...........|............................|...|..........
...........+<---------------------------+<--+..........
...........|............................|..............
...........|.......Answer...=...........|..............
...........|..DoYouHaveCheeseBurger()...|..............
...........+--------------------------->+---+..........
...........|............................|...|..........
...........+<---------------------------+<--+..........
...........|............................|..............
.......................................................

Class Diagram:

...........................................................
....+-------------------------------------------------+....
....|                    <<class>>                    |....
....|                FastFoodTerminal                 |....
....+-------------------------------------------------+....
....| [+] void: FastFoodTerminal();   <<constructor>> |....
....| [#] int: ObtainMoneyDifference();               |....
....| [+] void: ReceiveMoney();                       |....
....| [+] void: ReturnChange();                       |....
....| [+] FastFoodTerminal: TurnOn(); <<static>>      |....
....+-------------------------------------------------+....
...........................................................

In this example, the "TurnOn()" is an static method that returns, an instance (object) of the "FastFoodTerminal" class.



回答2:

So finally it is the use of stereotype to mention a static class/function. Underlining is no more applicable in UML 2.4.1 Aug 2011, page Page 86, under the headings Notation and Presentation Options



回答3:

I think your comment covers most of it:

UML 2 Sequence Diagrams: Notice how object labels are underlined, classes and actors are not It sounds like static class or call to a static function is represented with same stereotype provided 1- the name part of the pattern name:ClassName should be empty 2- It should not be underlined.

UML cannot cover this entirely because static is not a UML definition, each language has slight variances. However the UML spec for "features"[pg. 69] (attr/operations):

isStatic: Boolean -- Specifies whether this feature characterizes individual instances classified by the classifier (false) or the classifier itself (true). Default value is false.

Notice that they say the classifier itself. So the question is can I put a classifier a sequence diagram, not an instance? Also notice that is does not say classifier can be static. Page 27 of the same UML spec shows no isStatic in the meta class "classifier" (class). So UML does not provide a formal model feature for static classes. You can use stereotype or keywords, or your own UML profile and extend Class. But the short answer is do what you already posted.