Home > Mobile >  How to show that which class's variables are used in which class's operation(s) using UML
How to show that which class's variables are used in which class's operation(s) using UML

Time:10-28

There is a class diagram that contains one class and this class has three operations (Oper1, Oper2, and Oper3) and three attributes (Attr1, Attr2, Atrr3). Now suppose:

1- Oper1 uses Attr1 and Attr2 to read from and write to them, 2- Oper2 uses Attr3 to read from and write to it, 3- Oper3 uses Attr1, Attr2, and Attr3 to read from and write to them.

Now how can I show this dependency/usage of attributes in class's operations in UML diagram? Is it necessary to show this kind of relation in UML?

CodePudding user response:

This kind of relationships are not documented in an UML class diagram. The class diagram defines the properties and the operations, but not how they relate in a particular implementation.

May be today oper1 uses Attr1 and Attr2; but maybe tomorrow it will also use other properties. You may however document this in a comment note, or --perhaps better-- in UML pre-condition and post-condition constraints.

CodePudding user response:

If you want to just model the dependency, you certainly can do it. Either in a class diagram: class with dependencies between operations

Or in a matrix

dependencies shown in a matrix

Or simply in the model:

enter image description here

You could also define an activity as a method for each operation, which accesses the attributes with ReadStructuralFeatureActions and WriteStructuralFeatureActions. However, this would only add meaningful information, if you really want to completely specify the operations with this. Is this effort warranted?

  • Related