代表UML类图中一个C#泛型方法 [英] Representing a C# Generic Method in a UML Class Diagram

查看:470
本文介绍了代表UML类图中一个C#泛型方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下接口:

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



用户是一个抽象类和 ICanLogin 是另一个接口。

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

现在,我要代表与其在方法上图界面UML类图,在Visio。

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 ?

推荐答案

UML不直接支持的类型参数的方法。

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

这篇关于代表UML类图中一个C#泛型方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆