patr1c1a
patr1c1a

Reputation: 237

How to handle String collections in UML?

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?

Upvotes: 1

Views: 1310

Answers (1)

Gerd Wagner
Gerd Wagner

Reputation: 5683

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.

Upvotes: 1

Related Questions