Question

I have the following interface:

public interface IRegisterable
{
   T Register<T>(string username, string passw) where T : User, ICanLogin, new();
}

User is an abstract class, and ICanLogin is another interface.

Now, I want to represent the above interface with its method in a UML Class Diagram, in Visio.

How can I represent the above generic method with its constraints in a Class Diagram ?

Was it helpful?

Solution

UML does not support type parametric methods directly.

About the closest you'll get is to define a nested class which has the type constraints with a stereotype which you will interpret as meaning it's a type parameter, and define the Register operation in terms of that.

+---------------------------------------------------+
|                   «interface»                     |
|                  IRegisterable                    |
+---------------------------------------------------+
| + Register (string username, string passw) : T    |
+---------------------------------------------------+

    +---------------+           +---------------+
    |  «abstract»   |           |  «interface»  |
    |     User      |           |   ICanLogin   |
    +---------------+           +---------------+
            .                           .
           /_\                         /_\
            |                           .
            +-----------+   .............
                        |   .
                +-------------------+              
                |  «typeParameter»  |
                | IRegisterable::T  |
                +-------------------+           
                | + new()           |
                +-------------------+           

    note: T is a nested class within IRegisterable

OTHER TIPS

UML DOES support parametric types (other things can be parametrized as well, and things other than types can be used as parameters as well).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top