4

Let's say we have a table of countries. Each country has a name, a short name and some kind of code, e.g. by ISO. In UML, I can model the country names as an enum, the short names as an enum and a third enum for the country codes. But then I always have to keep these three enums in sync. Bad idea.

So, how to I model this more elegantly? Is there a way to model 'tables' in UML or do I have to make these enums nested somehow?

glasklar
  • 41
  • 1
  • See the solution provided in https://stackoverflow.com/questions/37159109/uml-modelling-enumeration-with-attributes – nize Oct 04 '21 at 09:51

1 Answers1

1

You will model that via properties

enter image description here

The Country class (I left out the attributes like name) will return the country code via a property Code which depends on the according enum. Other coding (with according naming) would be return in the same manner.

You need to decide on some leading coding (say it would be CountryCode. In order to get other codings you would need to provide operations to either Country or CountrCode like asISO():String and the like. This is a design decision. If you have independent codings which do not have mappings to each other you will run into trouble.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Well, that's not what I intended to say. In your example, I should have the class Country with the attributes Name():CountryName as well as Code():CountryCode. CountryName and CountryCode are enumerations, right. But in both the positions of name and code have to be in sync e.g. the first entry has to be UK for CountryCode and United Kingdom for CountryName. When I insert an entry in CountryCode at e.g. position 243, I have to do the same at CountryName. It might be a more elegant model to have some kind of table with two columns, one for the name and one for the code. Is this possible in UML? – glasklar May 25 '20 at 08:57
  • You need to decide upon a leading code. The rest would be mapped. You can add functions to `CountryCode` to return other codings. Will make an edit. – qwerty_so May 25 '20 at 08:59