Title: Object Oriented Design Heuristics
1private double amountFor(Rental aRental) return
aRental.getCharge()
- initially replace the body with the call
- remove this method later on and call directly
while (rentals.hasMoreElements()) double
thisAmount 0 Rental each (Rental)
rentals.nextElement() thisAmount
each.getCharge() the rest continues as
before
2frequent renter points
- Lets do the same thing with the logic to
calculate frequent renter points - extract method
- each can be parameter
- frequentRenterPoints has a value before the
method is invoked, but the new method does not
read it we simply need to use appending
assignment outside the method. - move method
- Again, we are only using information from Rental,
not Customer, so lets move getFrequentRenterPoint
s to the Rental class. - Be sure to run your test cases after each step
3// add frequent renter points frequentRenterPoint
s // add bonus for two day new release
rental if ((each.getMovie().getPriceCode()
Movie.NEW_RELEASE)
each.getDaysRented() gt 1) frequentRenterPoint
s // show figures for this rental result
\t each.getMovie().getTitle() \t
String.valueOf(thisAmount)
\n totalAmount thisAmount // end while