In my Visio 2007 UML document I am unable to figure out how I can add an operation to an Interface that returns a generic List<MyCustomType>
type.
For example:
Say I have a class named "MyClass" and an Interface named "IFace". IFace has a signature of a method that returns a Generic List of MyClass.
For clarity, here's an example of the C# code:
namespace StackO
{
public interface IFace
{
List<MyClass> SomeMethod(string data);
}
public class MyClass
{
}
}
Here's a screenshot of where I'm stuck:
It seems as though the only way to specify a List<MyClass>
as my Return Type is to create another user-defined datatype that is explicitly written as List<MyClass>
. If this is the case, so be it. However, I'm posting this in hopes that there is a better/proper way to do this.
How can I define the Return Type of an Operation of a Visio Interface to be a Generic List of a User-Defined Datatype?
In the Class diagram properties > Go to operations > select the return type you are interested in changing and click properties.
In the next dialog you will have option for setting prefix List<
and suffix >
.
This way you can specify the return type as List<>
.
I see this option in Visio 2010. But I am not sure if this option is available in Visio 2007.
There is no such a thing as T1<T2>
in UML class diagrams.
If you want to specify that the method returns several values, the correct notation is:
SomeMethod(data: String) : MyClass [*]
This notation is much more powerful than the one used by C#. List<MyClass> SomeMethod(string data)
gives no information about the contract of the method. With UML, you know that in:
SomeMethod(data: String) : MyClass [*]
SomethingElse() : String [1..*]
LastExample(number: UnlimitedNatural) : Integer [0..1]
SomeMethod
returns a sequence containing zero or more elements. SomethingElse
returns a sequence of one or several elements: this sequence is never empty. Finally, LastExample
returns an optional value. This could be expressed in C# as int? LastExample(uint number)
— see, no IEnumerable
here.
Also note that:
SomeMethod(data: String) : MyClass [0..*]
shouldn't be used, since [*]
means the same thing and is shorter. As for:
SomeMethod(data: String) : MyClass [0..n]
is incorrect, despite being used a lot on the internet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With