2

How do i model a call to a static method in a class diagram ? Can someone show me a link to a class diagram that has done that?

for example there's a class called Animal. and i have another class called Vertibrates, and it has a method which is static (and this is the only method in that class). My Animal class will be using this static method of the class Vertibrate. Therefore how can i model it in class diagram ?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
user1315906
  • 3,374
  • 8
  • 30
  • 43

3 Answers3

8

You don't. Well, not in a class diagram at least. Instead, you should use sequence chart diagrams to express method calls (whether static or dynamic).

  • So that class (class that has the static method) will be there in the class diagram with no connection to any other classes. Is that Ok ? – user1315906 Dec 20 '12 at 13:46
  • This is just one of the list of things UML doesn't do. Don't get me wrong, UML is much better than nothing. I just reckon there is more to do, the job isn't complete yet. :-) – will Dec 22 '12 at 14:00
2

You can't model the call directly in a class diagram (as @Imontrieux says), but you can model the relationship (i.e., that Animal uses (calls) static methods in Vertibrate; BTW, the correct spelling is Vertebrate), which I suspect is actually what you meant.

You use a UML dependency for this, not an association (since the latter are for associations between instances of the classes at each end)--- see How to show usage of static methods UML Classdiagram.

Community
  • 1
  • 1
Stuart Rossiter
  • 2,432
  • 1
  • 17
  • 20
0

Great question. One thing the GoF do in Design Patterns is used notes to demonstrate intended uses. For example, from the section on the Command Pattern:

Command Pattern

While @user1315906 is technically correct that you don't model such things in Class Diagrams, but rather in Use Case or Sequence Diagrams, if it makes sense to note how something is intended to be used in a Class Diagram, you can use a note :)

adam.hendry
  • 4,458
  • 5
  • 24
  • 51