On a UML diagram, what is the correct way to represent a template class?
Asked
Active
Viewed 3.2k times
2 Answers
93
Normal rectangle with a dotted rectangle in the top right corner, to represent the template parameter. Something like this:
.......
___________: T :
| :.....:
| |
| ClassName |
| |
|______________|

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
I've just realised that posting a link on Twitter could be counted as rep-scamming. Except that I hit the limit for the day *ages* ago... all I can really get is the 15 points for having it accepted (hopefully). Corollary: maybe I should actually have tweeted it at 12.01 UTC ;) – Jon Skeet May 13 '09 at 21:42
-
1Don't you hit the rep limit every day? – Kibbee May 14 '09 at 00:46
-
1Yes, but the earlier it happens in the day, the more likely it is that any accepted answer will contribute the +15 beyond the limit rather than *to* the limit. – Jon Skeet May 14 '09 at 05:21
-
1Where did you take this from, @JonSkeet? Could you please say why you consider this UML? – gustavogbc Mar 30 '17 at 00:07
-
1@gustavogbc: Given that it was nearly 8 years ago, I can't remember the source I'm afraid. But given a brief search, it *may* have been http://www.uml-diagrams.org/template.html – Jon Skeet Mar 30 '17 at 05:58
2
A more useful approach is to use a UML Classifier for the Template. This is a UML Element that represents an extension to the UML notation. If your tool supports profiles create the Classifier within one. Define the Classifier for the Template, and include the properties and methods from the template, then instead of using the standard class notation, use the Classifier you have created for each Class that uses the template. This would be correct usage of the UML for Templates.

Martin Spamer
- 5,437
- 28
- 44