Exercise
Return to the exercises 7,
7, and 7.
Follow the design recipe for abstractions: highlight the differences in the class definitions, and observe the similarities.
Design the interface IPriced
that contains the method
price()
. Assume the price is given in cents as a whole
number.
Rewrite the classes in exercises 7,
7, and 7, so
that they now implement the IPriced
interface.
Develop the class hierarchy to represent a list of objects
from classes that implement the IPriced
interface.
Develop the method totalPrice
that computes the
total price of all items in this list.
Rewrite the examples from exercises
7, refex:methods-shoppinglist, and
7, using the list of Object
s.
Design the methods lowerPrice
and cheaperThan
in the classes that represent the list of
IPriced
objects.
Design the necessary abstractions to implement the
sort
method in the classes that represent a list of
Object
s. You can use the price
method, or
design and implement an additional interface.