Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing a C# Generic Method in a UML Class Diagram

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 ?

like image 254
Andreas Grech Avatar asked Jan 17 '10 10:01

Andreas Grech


People also ask

What is C represent?

Carbon is also an element of periodic table which is represented by "C".

What does C mean in math algebra?

The Latin small letter c is used in math to represent a variable or coefficient.

What is the i in math?

Unit Imaginary Number The square root of minus one √(−1) is the "unit" Imaginary Number, the equivalent of 1 for Real Numbers. In mathematics the symbol for √(−1) is i for imaginary.

How do you represent imaginary numbers?

The notation “i” is the foundation for all imaginary numbers. The solution written by using this imaginary number in the form a+bi is known as a complex number. In other words, a complex number is one which includes both real and imaginary numbers.


2 Answers

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/

like image 148
salgo60 Avatar answered Nov 05 '22 09:11

salgo60


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
like image 45
Pete Kirkham Avatar answered Nov 05 '22 08:11

Pete Kirkham