Suppose I have a function like this:
public AddComponent<T extends Component>(type: T) {
//do stuff
}
How would I represent that in an UML diagram? For a normal function, I would write something like this:
+AddComponent(object: Component): void
edit: To make my question a littel clearer, here is an example of a class in my UML sheet.
(sorry, I'm just learning to do this now)
First of all, and not related to your question: you shouldn’t use a line separator between different groups of operation: keep it to distinguish properties and operations.
The UML specifications are unfortunately not fully clear about templates and their semantic.
The semantics are defined in section 7.3.2. that defined templates and their binding as being some kind of substitution.
It defines the notation of template operations in section 9.6.4. This is what you are looking for:
MyQuestionFunction < T: Class > (arg:T)
It also defines concrete bindings if you would have to use them:
MyQuestionFunction << T->Component >> (arg: Component)
But it doesn’t foresee to specify a constraint on the template argument, saying that T
must be a Component
. So IMHO it seems to be aligned more with the C++ kind of templates in which the type arguments are not explicitly constrained. You could eventually document a general UML constraint in natural language next to your function: {T extends Component}
The BNF specifications provided in that section furthermore documents how to specify an operation as template parameter, but seems incomplete in regard of the basics.
Coming back to your diagram, note also that the UML standard profile :
void
return type. In strict UML, a void function is just shown without any return type at all. int
primitive type but the Integer
instead.But very frequently, modellers use types of the implementation language, assuming a language-specific profile that would extend core UML with the missing types. If tou chose this approach you may very well keep your templated function as you have defined it.