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?
-
What do you mean by "wrong"? Doesn't violate the UML spec as far as I know. The pointers are still member variables. At a more conceptual level, I read this as "each Agent has an Ability, a Move and a See". Whatever those mean. More to the point: does it work for you & your audience? Do you all know what you mean by it? If so then it's fine. – sfinnie Aug 20 '13 at 15:08
-
Thanks @sfinnie, I searched the internet but could not find anything about using objects in class diagram, is underlining the object correct within the class attributes? – Stephen Jacob Aug 20 '13 at 16:42
-
Have provided answer, more appropriate than comment. – sfinnie Aug 20 '13 at 20:41
1 Answers
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.

- 9,854
- 1
- 38
- 44
-
Also remove the '*' in attribute names. If your attribute is typed by a class, it is a reference to an instance of this class, so no need (and it is illegal) to add '*' to say it is a pointer. – Xaelis Aug 21 '13 at 09:41