Pergunta

How to represent indexed or parametrized attributes in UML?

For example, how to reverse the following Java code:

 class MyClass {

       Object getValue(String key);
       void setValue(String key, Object value);

 }

From the one hand I can describe it simple

enter image description here

but this will not show that these 2 methods are related.

From the other hand I can describe it

enter image description here

but this will hide the fact, that multiple instances of a value are named by key parameter.

The similar problem arise with the following C# code:

class MyClass
{
    public string this[int i]
    {
        get
        {
        }
        set
        {
        }
    }
}
Foi útil?

Solução

There isn't a great answer for this since this class is in effect a dictionary/hash. A discussion of options you can choose be found here:

How to represent a .NET dictionary type in UML? or possibly this (as referenced): How to describe a contained map in UML class diagram?

Outras dicas

If I understand, you are now concerned with instances of your class (an instance for each key/value). Instances are prefixed w/a colon. To use your example they could look like MyClass:MyInstance

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top