July 2013
Intermediate to advanced
144 pages
4h 50m
English
The examples we looked at in Chapter 3, such as Fraction and Complex (despite its name), are simple because they’re closed under all four arithmetic operations. Whenever x and y are Complex objects, then x+y, x-y, x*y, and x/y are also Complex objects (except for division by zero). We didn’t have to think about which arithmetic operators to implement and what their results should be.
Most numeric data in the real world, however, have some unit of measure. An amount of money may be measured in dollars, a distance in meters, and a temperature in degrees Kelvin. Such data are rarely closed under all ...
Read now
Unlock full access