Geometry classes reconsidered
Starting in Modeling geometry objects: Rectangles you implemented rectangle and circle related classes. You may have observed translation related parameters to be shape independent.
Our Rectangle and
Circle instances are being described by width, height and
radius. Implementing a drawing application requires
arbitrary objects to be moved from one position to
another e.g.:
We might implement translation (move) related parameters and methods in both classes Rectangle and Circle independently. But since the underlying operation is indeed shape independent we choose a different approach using inheritance in the subsequent exercises.
No. 167
Defining a Shape class hierarchy
|
Q: |
Our two geometric primitives circle and rectangle will
need a reference point (x,y) to define
We thus need two additional parameters
x and y representing
an object's position. Consider the following inheritance diagram
and implement the three Java™ classes
Create unit tests checking for correct implementation of the translation example from Figure 499, “Moving shapes ” and the all other methods. Why is TipThink of multiple / combined operations. |
|
A: |
Defining |
