UML Class Diagram and Generics

我是研究僧i 提交于 2019-11-26 15:52:58

问题


How do you indicate a generic class or interface in a Class Diagram?

I'm looking for two things really:

  1. One is how do I model generic java classes if i were doing it with pen and paper.
  2. Secondly, what uml tools out there support generic classes/interfaces.

Thanks!


回答1:


Usually generics are represented as classifier's template parameter. Here is the example how it looks like in the NetBeans UML Plugin:




回答2:


UML calls them parameterized types - see examples here.

As for tools, I know MagicDraw supports them.




回答3:


UML template will help !

Defining Generics with UML Templates
http://www.eclipse.org/articles/article.php?file=Article-Defining-Generics-with-UML-Templates/index.html




回答4:


One is how do I model generic java classes if i were doing it with pen and paper.

AFAIK there is no specific support for this in UML, the best may be to use a stereotype like <<generic>>. But on paper with pen, there is nothing simpler than writing MYType<T> :-)

Secondly, what uml tools out there support generic classes/interfaces.

Stereotypes are supported by all UML tools I have seen so far. Of course, the level of support may differ; however, since I hardly use any UML tools apart from napkins :-) I don't have much base for comparison here.




回答5:


I'm looking for two things really: One is how do I model generic java classes if i were doing it with pen and paper.

Craig Larman's book Applying UML and Patterns 3e has instructor slides with the Figures from the book. The following is from Figure 15.5:

Secondly, what uml tools out there support generic classes/interfaces.

I like PlantUML, which will produce the following image from

skinparam style strictuml
participant sales as "sales:\nArrayList<Sale>"

For class diagrams, it produces

skinparam style strictuml
hide empty members
class "ArrayList<Sale>" as S
class Store {
Store()
}
Store "1" -> "1" S : "            sales  "




回答6:


In Netbeans The object to use is called "Derivation Classifier". This is the object to use for MyGeneric in Answer from Vitalii Fedorenko




回答7:


One is how do I model generic java classes if i were doing it with pen and paper.

It is generalization arrow, base class, if it is abstract, should be written in italics. Also can be marked with stereotype.

Secondly, what uml tools out there support generic classes/interfaces.

Use http://staruml.io/. Really nice tool, you can manage all project diagrams in one place. At right top corner, there is object/diagram tree, so you can use same classes(other objects) at different diagrams.



来源:https://stackoverflow.com/questions/4786771/uml-class-diagram-and-generics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!