CS Example - Complex Numbers

Let us take another example that is more related to computer science. Consider a language, such as Smalltalk, that has two abstract classifications. The first is the class Magnitude, that represents things that can be compared to each other. The second is the class Number, that represents things that can perform arithmetic.

Now consider three specific classes. An integer is both comparable and can perform arithmetic. A character is comparable, using the ASCII ordering, but cannot meaningfully support arithmetic. A complex number can support arithmetic, but the notion of comparison is not well defined.

There seems to be no way to place these three ideas into a single parent inheritance hierarchy so that Integer is a subclass of both Magnitude and Number, Char is a subclass of Magnitude but not Number, and Complex is a subclass of Number but not Magnitude.

[audio] [real] Text to accompany slide3, in Chapter 13 of An Introduction to Object-Oriented Programming