In short:
UML uses class templates for this purpose:
For this to work, you'd have to define somewhere (in a C# profile?) that NewConstraint
is a special interface that requires the implementing class to have a parameterless constructor. Alternatively, you could skip this the NewConstraint
and add a simple UML constraint (e.g. a note with the constraint in plaintext { T shall have a parameterless constructor }
)
Some more explanations about template parameters
More on the syntax of UML classifier template can be found in the UML specs (page 103):
A ClassifierTemplateParameter extends the notation for a TemplateParameter to include an optional type constraint:
<classifier-template-parameter> ::=
<parameter-name> [ ‘:‘ <parameter-kind> ] [‘>’ <constraint>]
[‘=’ <default>]
<constraint> ::= [‘{contract }’] <classifier-name>*
The parameter-kind indicates the metaclass of the parameteredElement. It may be suppressed if it is ‘Class.’
The classifier-name of constraint designates a constrainingClassifier
, of which there may be zero or more, with the meaning specified in the semantics above. The ‘contract’ option indicates that allowSubstitutable is true.
Since I misunderstood the {contract}
myself, and first confused it with an ordinary constraint, let's clarify this important hint:
{contract} xxx
means that the parameter allows the substitution of the parameter with a classifier having the same contract than xxx
. This is needed when a paramter is a class that is constrained by specific interfaces.
xxx
(without {contract}
) means that the parameter is required to be xxx
or a specialization of it. In consequence, this cannot be used for a class that has to implement an interface, since the class is an implementation of an interface and not a specialization.
In your case, the parameter would then be:
T : class > {contract} IModel NewConstraint
But since class is the parameter-kind by default, it could be simplified to:
T > {contract} IModel NewConstraint