We have to be able to do arithmetic on Units. For example, suppose we have a some_distance instance of Distance, and we want to double it.
Here is one kludge:
Distance(2*some_distance.raw_value, Distance.Inch) << some_distance.unit
Problem: We have to read through the Distance class to see that its raw_value is in units of Distance.Inch.
Solution: Give all AbstractUnits child classes a raw_units property (can be static) that returns the raw units for the subclass. For example, Distance.raw_units would return Distance.Inch. Then we could instead do:
Distance(2*some_distance.raw_value, some_distance.raw_units) << some_distance.unit
We have to be able to do arithmetic on Units. For example, suppose we have a
some_distance
instance ofDistance
, and we want to double it.Here is one kludge:
Distance(2*some_distance.raw_value, Distance.Inch) << some_distance.unit
Problem: We have to read through the
Distance
class to see that itsraw_value
is in units ofDistance.Inch
.Solution: Give all
AbstractUnits
child classes araw_units
property (can be static) that returns the raw units for the subclass. For example,Distance.raw_units
would returnDistance.Inch
. Then we could instead do:Distance(2*some_distance.raw_value, some_distance.raw_units) << some_distance.unit