You have several classes providing the same functionality in the same
way. The parent is a very generalized version of the children, so it
doesn't make sense to build concrete cases of one. Ex: Car - We talk
about driving cars, but we are really driving very specific instances
of cars. There is no "car" objects, they are sedans, station wagons,
vans, etc. You can even get down to specific model numbers.
polymorphism
When you have a class family that shares common methods, one can
talk about polymorphic behavior. The particular version of the
method that executes at run-time will be the method that is most local
to the calling object. If that object has its own implementation
of the method, that implementation is used. If not, the
inheritance chain is searched for the closest object containing the
method. So we would say that method foo in a family of classes, fooble, has polymorphic behavior.
Given a problem statement such as: "You need to make an
application that will provide geometry services. We need to be
able to create different objects, such as a Sphere, a Triangle, and a
Line, and perform some geometric statistics on those objects." How
would you decide what is the superclass and which are the subclasses.
Think of the case of the Sphere with a superclass of Circle
(which is a 2D object) and Pyramid with a superclass of
ThreeDimensional object.
Which is better and why?
How do you choose the class hierarchy?
How do you choose which methods to override?
How do you decide what makes sense as an abstract class and what should be concrete classes?
Activities
Using the diagram, answer questions about the class family.
Using the diagram, predict which lines are valid and which are not.
Using the diagram, predict what would happen if...
Design a family of classes given the problem statement.
Share your responses to the design with the class on the board.