How do you indicate a generic class or interface in a Class Diagram?
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.
- Secondly, what uml tools out there support generic classes/interfaces.
Thanks!
Usually generics are represented as classifier's template parameter. Here is the example how it looks like in the NetBeans UML Plugin:
In Netbeans The object to use is called "Derivation Classifier". This is the object to use for MyGeneric in Answer from Vitalii Fedorenko
UML calls them parameterized types - see examples here.
As for tools, I know MagicDraw supports them.
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
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 writingMYType<T>
:-)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.
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:
I like PlantUML, which will produce the following image from
For class diagrams, it produces