1

I've always wondered what would be the best way (and I mean a standard, OMG approved way) to model a String collection in UML. Let's say I have a simple design where there are quotes, each one of them represented by several keywords. So I model a "Quote" class, with the quote itself (a String), the name of its author (another String) and a collection of keywords (being each one of them Strings as well). If I want to show the String multiplicity in my "keywords" attribute, I'd have to add in my design the "String" class. But since this is a built-in class in most languages, I'd just leave it empty because I don't know how it is actually implemented. So I'd have something like this: String class in UML

It looks a bit awkward to me... Is there a better (standard UML) way to model this?

patr1c1a
  • 237
  • 4
  • 16

1 Answers1

1

It's not true that "If I want to show the String multiplicity in my "keywords" attribute, I'd have to add in my design the "String" class." There is no need for modeling such an association with a String class.

You simply specify the * as the multiplicity of your multi-valued keywords attribute and it will be shown in your Quote class rectangle as

quote[1] String
author[1] String
keywords[*] String

Notice that in your diagram the attributes' multiplicity is not shown, so it's 1 by default.

Gerd Wagner
  • 5,481
  • 1
  • 22
  • 41
  • Thanks for the reply, gwag. In this case, I have a new conundrum: let's say I have another class I built, the "Author" class and a quote can have more than 1 author (not too realistic, but just to keep the same example). In this case, should I also add the "author" collection attribute the same way as String collections? Or now I should mix both ways of representing collections, like this: http://snag.gy/SQ8AB.jpg My concern here is that I'd have 2 different ways of representing collections, mixed in the same diagram. Please remember I'm looking for the standard way to do this in UML. – patr1c1a Apr 13 '14 at 22:28
  • Indeed, in a UML class diagram, a (unidirectional binary) association with another class can be represented either as an association line or as a reference property, see also [this answer](http://stackoverflow.com/a/21817541/2795909) or [my tutorial on unidirectional associations](https://oxygen.informatik.tu-cottbus.de/IT/JsFrontendApp/unidirectional-association-tutorial.html). But you shouldn't mix these two ways of representing an association. The first representation is more conceptual and more visual, while the second goes already one step towards implementation. – Gerd Wagner Apr 14 '14 at 11:49