UML Class Diagram and Generics

2020-01-29 04:53发布

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!

标签: java uml
7条回答
家丑人穷心不美
2楼-- · 2020-01-29 05:00

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

enter image description here

查看更多
beautiful°
3楼-- · 2020-01-29 05:03

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

查看更多
贼婆χ
4楼-- · 2020-01-29 05:06

UML calls them parameterized types - see examples here.

As for tools, I know MagicDraw supports them.

查看更多
老娘就宠你
6楼-- · 2020-01-29 05:16

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.

查看更多
太酷不给撩
7楼-- · 2020-01-29 05:17

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:

enter image description here

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>"

enter image description here

For class diagrams, it produces

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

enter image description here

查看更多
登录 后发表回答