As a converter, the units of measurement are data and do not actually belong to the code.
You can do some really awesome things, however, if you break your units into βbasicβ components (length, temperature, time, ...)
So you may have a database that looks like this:
minute = 1 x Time (where Time is the base unit of time)
second = time / 60
hour = time * 60
meter = 1 x distance
Clometer = 1000 x distance
...
The best part is that you begin to get real flexibility with formulas. For example, if I had some kind of information around, like the fact that the snail I was observing moved 20 cm in 3 minutes, I could easily pass this to the speed equation (speed = distance / time) to get βRootβ speed number, then request the results in terms of different units (for example, miles and hours) so that I instantly get the result in miles per hour.
You even know what information you donβt have - for example, if you give a distance and ask for speed, she may say "you still need time." Or, if you give distance and speed, it can calculate the time in units of your choice.
In any case, all the data. You probably shouldn't even have different classes for distance and time.
I believe that I would use a fixed set of measuring objects, as described above, which could be used to search for conversions (unit name, unit type, conversion factor), for example ("Minutes", TIME, 1)
When the user enters a value with a unit (let them say that the user enters 3 hours), I just look at the block ("Clock"), compute the conversion (180, TIME) and save (180, TIME) somewhere.
When they requested a countdown in a few minutes, I looked at the conversion in minutes ("Minutes", TIME, 1) and used a scaling factor (1) to determine that you need to print 180 minutes.
If the user set a value of 3 hours and asked for speed in meters per second, you can request a distance (which the user can specify using any type of distance) and easily convert to the desired result. Converting to base units and using scaling factors almost completely eliminates the difficulties.
Justification / Argumentation:
My assertion that units and conversion factors should not be indicated in the code is likely to be called into question ...
My reasoning is that you should NEVER have objects that do not have a single business logic.
The only difference between minutes and seconds will be a formula that will only change in constant (at any given time you can use the second x 60 or hour * (1/60), so the constant (1, 60, 1/60) cannot create a new class in itself would be absolutely criminal.
This applies to all major types of measurements; none of them have a unique business logic.