2

I have a short question:
Should I name attributes of types like a List, Arrays, Vectors or Pointers to objects (not primitive type) in the UML diagram or the only association/aggregation/composition arrows are enough?

Example: which of these diagrams is correct?

enter image description here

or

enter image description here

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
Derek K
  • 2,756
  • 1
  • 21
  • 37

2 Answers2

2

In UML, your second diagram would be correct if you wrote the property names at the far ends of the associations. While UML properties are allowed to be unnamed, it is not a good practice. Use association ends to indicate why the relationship exists. Sometimes more than one association must exist between one pair of classes, but for different reasons. How would you tell them apart?

The first diagram shows two properties of each type. One is named and another (at the end of each association) is unnamed. That is incorrect.

Jim L.
  • 6,177
  • 3
  • 21
  • 47
  • Thanks. What do you mean by telling "at the end of each association"? Could you show any correct example? Both first and second diagrams show aggregation and composition (Class4 has pointers to Class5 and Class6 but Class6 and Class5 don't know Class4) – Derek K Jan 16 '16 at 13:44
  • For examples of association ends, see http://stackoverflow.com/questions/34252780/what-is-the-common-way-to-represent-this-kind-of-diagram/34256880#34256880 . For an explanation of composition and aggregation, see: http://stackoverflow.com/questions/1644273/what-is-the-difference-between-aggregation-composition-and-dependency/1644321#1644321 – Jim L. Jan 16 '16 at 15:27
  • Imho, the unnamed property on the class diagram means that the name will be the same as the name of its class. I haven't read as a rule, but it is widely used as an unsaid rule. – Gangnus Jan 21 '16 at 09:15
  • @Gangnus: In the UML 2.5 spec, it says there is a convention "adopted for all metamodel diagrams throughout this specification. [ . . . ] If an association end is unlabeled, the default name for that end is the name of the class to which the end is attached, modified such that the first letter is a lowercase letter." However, that is not a normative part of the spec, so one should *not* rely on it. – Jim L. Feb 10 '16 at 22:27
  • @JimL. Yes. But it is not a bad rule and you can rely on it in an organization that accepts it. And I have met it in some books where it was used implicitely. So, it is good to know about it. – Gangnus Feb 11 '16 at 12:48
0

This really depends on what you're trying to convey in this architectural drawing. The purpose of the drawing is to help reason about the structure of the software. It should not be used to represent all of the details of implementation. If you put too much detail in it, it becomes cluttered, and it is hard to keep it consistent with the source code as changes occur.

The UML drawing should be more abstract than the implementation. It should hide details on purpose, so that it conveys the external view of classes, and not how they are implemented internally. You generally don't want users of classes to assume too much about their internal implementation, therefore you don't want to expose it too much.

Also, an architecture is typically represented by several drawings - not one. Try to have each drawing focus on one level of abstraction. If you have a few high level classes that represent the main logic of the application, and many low level classes, it makes sense to have a drawing of just the high level classes separately.

Adi Levin
  • 5,165
  • 1
  • 17
  • 26
  • He is not putting much info. He is putting the same info twice. The first is bad style, the secone is so bad style, that can be considered as an error. – Gangnus Jan 21 '16 at 09:18