how to relate data with function in uml class diag

2019-08-03 01:44发布

问题:

I have two private data structures and five functions in my class, How can I represent the relation between the functions and the data structures in class. Eg: Two of those functions uses the First data structure and three other functions uses the second data structure.

Also How can I represent relation between the functions in the class. eg : among the 5 functions two are public and three are private, one public function in the class calls the other three private functions.

If this is not relevant in class diagram then what is the best solution to represent this in UML.

回答1:

the interaction of functions and fields is not displayed in a Class Diagram.

Therefore you should use a sequence diagramm. But normaly you do not show the interaction of fields within an Object. You display the interaction on the level of function calls between Objects.



回答2:

Two things. First, there's a good reason UML doesn't provide notation for depicting relationships & structure within a class. Classes are supposed to be cohesive abstractions of data and function. So if you have any significant structure within a class, you should question whether it should be split into 2 (or more) cohesively abstracted classes.

OK. So that's the backdrop. From your description, how about:

  • Draw one class for each data structure with one attribute for each structure member
  • Add a method to each class for each function that operates on the data structure
  • Add an association between the classes that captures their relationship
  • Place all the bits above in a package to represent the module

The final point - as in all these things - is to use the tool to illustrate what you want. Don't be overly constrained by the rules of the modelling language. The important thing is that the diagram communicates effectively to you & your collaborators. Satisfying the 'language lawyers' should be much less of a consideration.

hth.



标签: class uml