Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know how to do this in your tool of choice, but on the model level, it works exactly like for classes. You create a template operation with your signature. </p> <p>Chapter 17.4.14 of the <a href="http://www.omg.org/spec/UML/" rel="noreferrer">UML2 superstructure</a> specifies this for notation:</p> <blockquote> <p>The template parameters and template parameter binding of a template operation are two lists in between the name of the operation and the parameters of the operation.<br> *&lt;visibility> &lt;name> ‘&lt;‘ &lt;template-parameter-list> ‘>’ ‘&lt;&lt;‘ &lt;binding-expression-list> ‘>>’‘( ‘ &lt;parameter> [‘,’&lt;parameter>]** <em>‘)’ [‘:’ &lt;property-string>]</em></p> </blockquote> <p>In your case, let's first see the simple case of</p> <pre><code>public &lt;T&gt; boolean bar(T x, T y) </code></pre> <p>This would correspond to</p> <blockquote> <p>&#43; bar&lt;T> (x: T, y: T) : Boolean</p> </blockquote> <p>Your original example looks a bit more complicated because the template parameter is constrained to another class, Comparable, that in turn is also a template whose parameter (I'll call it T1) is bound to the operation's parameter in turn. This gives us</p> <blockquote> <p>&#43; bar&lt;T > Comparable&lt;T1->T>> (x: T, y: T) : Boolean</p> </blockquote> <p><br></p> <p><strong>Note:</strong> (<em>A bit of in-depth rambling ahead</em>) Templates as specified by UML (and to some degree C++) are a very different beast from Generics in Java. They look more or less the same, but there are - sometimes subtle - differences in their semantics that can make it difficult to match the two. The most important one in UML is this:</p> <blockquote> <p>A template cannot be used in the same manner as a non-template element of the same kind. The template element can only be used to generate bound elements (e.g., a template class cannot be used as the type of a typed element) or as part of the specification of another template (e.g., a template class may specialize another template class).</p> </blockquote> <p>This means that in UML, OtherFoo needs to be a template, too - i.e. have a template signature (with 0 parameters). In order to then use the operation template correctly outside the template scope - i.e. call it in an activity or similar - you'd first have to bind it to a concrete operation, which is used instead. In case of your example, this means:</p> <ol> <li>Binding OtherFoo template to an (anonymous) bound class.</li> <li>Binding bar operation template to an operation in the bound class.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload