What is the correct way to represent template classes with UML?

TemplatesUmlDiagram

Templates Problem Overview


On a UML diagram, what is the correct way to represent a template class?

Templates Solutions


Solution 1 - Templates

Normal rectangle with a dotted rectangle in the top right corner, to represent the template parameter. Something like this:

           .......               
___________:  T  :
|          :.....:
|              |
|  ClassName   |
|              |
|______________|

Solution 2 - Templates

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpaxos1977View Question on Stackoverflow
Solution 1 - TemplatesJon SkeetView Answer on Stackoverflow
Solution 2 - TemplatesMartin SpamerView Answer on Stackoverflow