This Web document was based on a set of "slides" created by the instructor for use in the Fall 1997 and spring 1999 offerings of the object-oriented design and programming course. That set was, in turn, based on a set of slides created by Timothy Budd to supplement chapter 13 of his textbook An Introduction to Object-Oriented Programming, Second Edition (Addison-Wesley, 1997).
Objects often characterized in different ways that are orthogonal to each other
For example, the instructor is
None of these are proper subsets of each other
Cannot be placed into an inheritance hierarchy
Two abstract classifications:
Magnitude
:
Number
:
Three specific classes:
Integer
:
Char
:
Complex
:
Number
subclass of
Magnitude
, but redefine comparison
operators in class Complex
to print
error message
-- subclassing for limitation
-- flattening the inheritance tree
Number
, but have each number
implement all relational operators
Number
and
Magnitude
independent, and have
Integer
inherit from both
-- multiple inheritance
____ Char
____|
|
Magnitude <--|
|
|____
|____
____ Integer
____|
|
Number <--|
|
|____
|____ Complex
Menu
is structure charged with
displaying itself when selected by users
Menu
maintains collection of
MenuItem
s
MenuItem
knows how to respond when selected
MenuItem
and
Menu
What happens when same name is used in both parent classes?
CardDeck
knows how to
draw
(select) a Card
GraphicalItem
knows how to draw
(display) an image on screen
GraphicalCardDeck
should be able to
draw
-- but which?
What happens when parent classes have common root ancestor?
Does new object have one or two instances of common ancestor?
____ InStream ____
____| |____
| |
Stream <--| |<-- InOutStream
|____ ____|
|____ OutStream ____|
Java supports multiple inheritance of interfaces (subtypes) but not of classes (subclasses)
interface A { ... } interface B { ... } interface AB extends A, B { ... } interface C { ... } class X { ... } class Y extends X implements AB, C { ... }
UP to Engr 691 Lecture Notes root document?