Should I use a enumeration in UML when a property can only take two values?

Viewed 38

We have a very concrete case in our UML diagram which is the MeasurementSystem property. It can be either the imperial or metric system and it is quite important. I wondered if I should make this an enumeration named MeasurementSystem which has Imperial and Metric in there. The other option is making it a boolean but it doesn't seem logical since it is not really a true/false situation but I am just wondering about if it is okay anyway.

1 Answers

Using an enum has three main advantages:

  • It is closer to the reality and less ambiguous: it's not about true/false but metric/imperial.
  • The alternatives are self-documenting
  • If at a later stage you want to use ancient Greek or Roman or Biblic measurement systems, it's easier to expand.

Using a boolean isMetric is easier to implement but it makes later evolution very difficult, once you have a lot of if ... else rather than switch case

Another possibility is to make a class MeasurementSystem with two specializations MetricSystem and ImperialSystem. You then don't have to foresee a lot of switch case but you could fully benefit from polymorphism instead.

Related