“46029˙CH12˙Miller” — 2008/7/29 — 13:15 — page 421 — #29
Programming Exercises 421
12.13 Implement the design for Polygon and its children.
12.14 Implement additional Polygon convenience classes such as Square, Triangle,
Rectangle and Octagon.
In this chapter we learned about inheritance, the ability to design and implement classes
so that they take advantage of natural relationships that may exist between them. These
relationships provide a way for us to organize our classes. Parent classes contain general
details (instance variables and methods) that pertain to an object. Child classes contain
details that allow objects to be more speciﬁc. This child-parent relationship, called an IS-A
relationship, allows child objects to have all the functionality of parent objects while adding
speciﬁc additional details.
abstract class inheritance hierarchy polymorphism
base class instance variables subclass
child class IS-A relationship superclass
HAS-A relationship methods
inheritance parent class
class None self
isinstance object super
12.1 Design and implement the Ellipse part of the shape hierarchy.
12.2 Design and implement a Text class for the GraphicalObject hierarchy.
12.3 Test your entire set of classes using Listing 12.1.
“46029˙CH12˙Miller” — 2008/7/29 — 13:15 — page 422 — #30
422 CHAPTER 12 Your Father Was a Rectangle
Using our graphics module, implement your own scene.
12.5 Using our graphics module, draw a rectangle and a circle inside the rectangle. Now
have the circle move inside the rectangle. If the circle touches the wall of the rectangle,
it should bounce oﬀ the wall in the appropriate direction.
12.6 Reimplement the bear and ﬁsh simulation from Chapter 11 using inheritance. Hint:
You will want to create an abstract class called LifeForm that captures the common-
alities of bears and ﬁsh.