如何将数据与uml类图中的函数相关联 [英] how to relate data with function in uml class diagram

查看:203
本文介绍了如何将数据与uml类图中的函数相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的类中有两个私有数据结构和五个函数,我如何表示类中的函数和数据结构之间的关系。例如:其中两个函数使用第一个数据结构,另外三个函数使用第二个数据结构。

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.

此外,如何表示类中的函数之间的关系。例如:在5个函数中有两个是public的,三个是私有的,一个公共函数在类中调用另外三个私有函数。

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.

如果这在类图中不相关那么在UML中表示这个的最好的解决方案是什么。

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

推荐答案

首先,有一个很好的理由UML不提供描述关系&类中的结构。类应该是数据和函数的内聚抽象。因此,如果你在一个类中有任何重要的结构,你应该质疑它是否应该被拆分成2个(或更多)cohesively抽象类。

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。所以这是背景。从您的描述中,如何:

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。

这篇关于如何将数据与uml类图中的函数相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆