UML Key Value Pair

The key-value pair structure can be modeled using the template parameters in Software Ideas Modeler.

To model generic structures like key-value pairs, we can utilize template parameters. Firstly, we need to decide whether we want to model a class or a structure (struct) and choose the appropriate tool from the UML class diagram toolbox. Then we can add desired template parameters to the created UML classifier.

Key-Value Pair in UML
Key-Value Pair in UML

In our example, we are modeling key-value pair structure, so we add two template parameters. To add a template parameter, click on the Add Template Parameter button in the context bar. Then type the parameter name - it's TKey in our case. The second parameter can be added in the same way, or we can press the Down key, and another parameter will be added without further clicking. Then we type TValue. Now, we can add fields for key and value to the classifier. Click on Add Attribute button in the context bar and add two attributes named Key with TKey type and Value with TValue type.

The last thing we should do is add a "property" stereotype to both attributes in the modeled structure.

Software Ideas Modeler allows you to generate source code for this structure using the Generation sidebar.

Defining Key Value Pair structure in UML
Defining Key Value Pair structure in UML

New Comment

Comment