Representing a C# Generic Method in a UML Class Diagram

后端 未结 3 1263
不思量自难忘°
不思量自难忘° 2020-12-10 15:02

I have the following interface:

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


        
相关标签:
3条回答
  • 2020-12-10 15:28

    A generic class is a Template class in UML see What is the correct way to represent template classes with UML?

    So can't you use thye Parameterized Class in Visio http://etutorials.org/Programming/UML/Chapter+6.+Class+Diagrams+Advanced+Concepts/Parameterized+Class/

    0 讨论(0)
  • 2020-12-10 15:30

    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
    
    0 讨论(0)
  • 2020-12-10 15:35

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

    0 讨论(0)
提交回复
热议问题