Quantities

Problem

Representing quantities such as "7 kilometers", "3 days", "98.6 degrees" as numbers is dangerous. We can forget if 7 represents miles or kilometers. If we want to internationalize our application, we will have to scrap most of our quantities.

Solution

A quantity should be a number together with a unit. Here's a reusable model:

We provide static predefined units. We depart from the metric system standard which defines seven basic units (meter, kilogram, second, etc.) and many derived (i.e., composite) units because these units are mostly geared for scientific applications rather than business applications. Also, many English-speaking countries still use traditional units like mile and pound.

Composite units can represent products and quotients of units such as square meters or miles per hour. Quantities can be compared, added, multiplied, etc. The Converters class is a utility that provides conversion routines between quantities.