对象作为类的数据属性在类图UML中 [英] Object as data attribute of class in Class diagram UML

查看:235
本文介绍了对象作为类的数据属性在类图UML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我添加一个指向一个类的对象的指针,作为UML中类图的类的数据属性,以下格式是否错误?

Is the following format wrong if I add a pointer to an object of a class, as data attribute of class in Class diagram in UML?

推荐答案


在类图中找不到使用对象的任何东西,是
,在类属性中强调对象是否正确?

could not find anything about using objects in class diagram, is underlining the object correct within the class attributes?

我认为你可能误解了类,对象和属性。道歉,如果这是我做错误理解。所以。这里是简短的答案:

I think you may be mis-understanding classes, objects and attributes. Apologies if it's me doing the mis-understanding. So. Here's the short answer:


  • 这是一个绝对正常的属性的类型是一个类。换句话说,你不局限于使用原始类型,如int,long,char等。

  • 结果是,正如你所说,运行时这些属性的值将本身就是对象。

  • 更具体地说,代理的每个实例(即每个代理对象)将保存对其他3个对象的引用 - 或更准确地说指针 -

因此,假设这是正确的,你有正确的 - 除了下划线。

So, assuming that's right, what you have is correct - except for the underlining.

下划线属性或操作说它位于类级别,而不是实例级别。它相当于java中的 static 。想想在类范围或构造函数中声明常量。

Underlining an attribute or operation says it sits at the class level - not the instance level. It's the equivalent of static in java. Think of declaring constants in class scope, or constructors.

如果我理解你的模型不是你想要的。您希望代理的每个实例保持(指针)自己的实例,移动和看见。您不希望所有代理对象共享相同的3个实例。假设这样,你不需要下划线。

If I understand your model that's not what you want. You want each instance of Agent to hold (a pointer to) its own instances of Ability, Move and See. You don't want all the Agent objects to share the same 3 instances. Assuming so, you don't need the underline.

希望我理解并帮助。

这篇关于对象作为类的数据属性在类图UML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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