Book a Demo

Author Topic: call static methods in sequence diagrams?  (Read 9618 times)

rabra

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
call static methods in sequence diagrams?
« on: July 24, 2006, 07:33:35 am »
Hallo,

my question is how or if at all I can depict the call of a static class in a sequence diagram. I know that in a sequence diagram the actions in the lifetime of OBJECTS is depicted. But calling these static methods is in my context very important - without the diagram would make no sense.
So is there a possibility for that or do you have an idea how I can depict the calls of static methods in another way?


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #1 on: July 24, 2006, 08:11:23 am »
This should not be an issue. UML allows the entities at the top of a sequence diagram to be either instances or classifiers. That is, you are not constrained to have objects, but can include classes.

If you've defined the class as static, or even if you are calling a static method of a class, this would appear to be the best approach. If you normally show explicity creation or destruction of entities, remember that you will not be doing so in this case.

Just make sure your class or method is depicted as static where it is defined in the overall model, or you'll be in for problems elsewhere.
No, you can't have it!

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #2 on: July 24, 2006, 04:09:53 pm »
This is actually a matter of "religion" rather than functionality.    I have (the same) moral objections to putting classes in sequence diagrams.

I just got over the matter by putting the static class in as an object, giving it a "null" name and setting its stereotype to static.  The moral rationalisation (to me) is that in a runtime situation, from the pov of the runtime a static class is actualy an object - as a singleton.... :o

Anyway - works for me.

bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #3 on: July 24, 2006, 05:59:07 pm »
Quote
This is actually a matter of "religion" rather than functionality.    I have (the same) moral objections to putting classes in sequence diagrams.

I just got over the matter by putting the static class in as an object, giving it a "null" name and setting its stereotype to static.  The moral rationalisation (to me) is that in a runtime situation, from the pov of the runtime a static class is actualy an object - as a singleton.... :o

Anyway - works for me.

bruce
As is the case, more often than not, FWIW, I agree with bruce... ;D

Paolo

BTW: bruce, «static» when applied to a class implies «singleton» doesn't it?  You could reinforce the singleton aspect by setting the Multiplicity (since Cardinality isn't emitted on the interface) of the class to "1".
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #4 on: July 25, 2006, 03:48:57 am »
Wise words, Paolo and Bruce.

To add another few cents (CAD) to this, I agree with both your sentiments. I was only pointing out that UML and EA permit you to use a classifier.

How you name and represent a static, or singleton for that matter, would appear to be a matter for individual organizations or applications (generally not developers) to determine. Whatever you do, be consistent! [Where have we heard that before?]

To pick a nit, I agree that a singleton shares much of its behavior with a static class, but with an important distinction: one of them must be created before use. Depending on various scoping issues and such this can make a difference, and might be worth explicit representation on (perhaps only one of) the sequence diagrams for the system.
No, you can't have it!

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #5 on: July 25, 2006, 03:47:04 pm »
He he he!  I knew including that comment on singleton would generate some interest.  

Actually, I meant to quote it - but forgot to.  I agree with Midnight entirely.

bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
Re: call static methods in sequence diagrams?
« Reply #6 on: July 26, 2006, 05:11:04 am »
Quote
This is actually a matter of "religion" rather than functionality.    I have (the same) moral objections to putting classes in sequence diagrams.
 
I just got over the matter by putting the static class in as an object, giving it a "null" name and setting its stereotype to static.  The moral rationalisation (to me) is that in a runtime situation, from the pov of the runtime a static class is actualy an object - as a singleton....


I agree that a static class is in effect nearly the same as a singleton.

However, if you are calling a static method of an otherwise non-static class, the two things are quite different. The static method can be called without the non-static data members of the class existing anywhere (never allocated, never initialized), and the non-static operations of the class can't be called. In this case, I would put the class, not an instance of the class, in the sequence diagram.

In the first case, the case of a static class, I would also put a class, not an instance, in the diagram. Since UML supports showing the facts as they are, why not do it? I don't see anything wrong in that.

However subtle the differences between a static class and a singleton, the differences are still there.

Best regards,
Mikkel