Object as data attribute of class in Class diagram UML

只谈情不闲聊 提交于 2019-12-24 12:17:42

问题


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?


回答1:


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:

  • it's absolutely fine and normal for the type of an attribute to be a Class. In other words, you're not restricted to using primitive types like int, long, char etc.
  • The consequence is, as you say, that the values of those attributes at run time will themselves be objects. Specifically, instances of the classes Ability, Move and See.
  • More specifically, each instance of Agent (i.e. each Agent object) will hold references - or more precisely pointers - to 3 other objects: one instance each of Ability, Move and See.

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

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.

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.

Hope I understood and that helps.



来源:https://stackoverflow.com/questions/18335314/object-as-data-attribute-of-class-in-class-diagram-uml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!