2

enter image description here

In the example I made every object of the type "Folder" have an array of type "File" with the name "content" a size of "n" as a private attribute (just saying my understanding of it to make sure that I am not already wrong there). That's how I see it in most examples but I never understand what "n" now is. Is it another attribute of the "Folder" object or is it something that we specify in another part of an UML diagram or something else completely?

What I am trying to achieve is that every object of the type "Folder" has an additional attribute that specifies the size of the "content" array.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
Ayren
  • 47
  • 5
  • That diagram is incorrect. The n should be 0..*. – Jim L. Jan 09 '17 at 00:33
  • @JimL. Thanks but still it seems like somehow there seems to be a way to put variables like n or m as Parameters for the multiplicity [as its mentioned here as an example](http://www.uml-diagrams.org/multiplicity.html) – Ayren Jan 09 '17 at 00:50
  • Multiplicity is a rule, not a variable. If you use a collection to represent the property "content", the collection will track how many things are in it. – Jim L. Jan 09 '17 at 00:55
  • @JimL. Ohhh ok now I get it. So it basically works like arrays in Java. Thanks alot – Ayren Jan 09 '17 at 01:01
  • Possible duplicate of [UML association multiplicity](http://stackoverflow.com/questions/9650657/uml-association-multiplicity) – qwerty_so Jan 09 '17 at 06:41
  • I think it is a good question - the use of a free variable defined externally or by constraints in comparison to simply setting a rule by its limits can be a powerful tool. – Gangnus Jan 10 '17 at 08:22

1 Answers1

1

Of course, you can not only write 0..*, but use any concrete number, too. If that number has some external definition, you can use there n, as you have it.

The external definition means "not defined by class diagram elements, except notes". Everything that you need to be said on a class diagram page, but can't because of the UML limitations, should be put in a note.

So, n can be defined in appropriate note on the page or in some different document or both.

As @Kilian had mentioned, in the case of some more complicated dependencies of such variables you can use constraints. This way seems to me the most powerful.

But if n has no objective definition or dependency, but is a simple variable that can have any meaning, then it will be correct to use a rule, such as 0..*, or 1..*, or maybe 3..5, according to the reality you are working with.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • 1
    You should mention that constraints can be used in such cases to express limitations or correlation between attributes and array dimensions. – qwerty_so Jan 09 '17 at 22:54
  • @ThomasKilian agreed and added to. :-) And I even consider them the most powerful tool. – Gangnus Jan 10 '17 at 08:21