January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
366
Refactoring Lecture 7 January 02, 2009 O b j e c t O r i e n t e - - PowerPoint PPT Presentation
366 Refactoring Lecture 7 January 02, 2009 O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g Refactoring: problem statement O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g Add a htmlStatment method
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
366
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
377
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
380
public String statement() { double totalAmount = 0; int frequentRenterPoints = 0; Enumeration rentals = _rental.elements(); String result = ÒRental Record for Ò + getName() + Ò\nÓ; while (rentals.hasMoreElements()) { double thisAmount = 0; Rental each = (Rental) rentals.nextElement(); thisAmount = amountFor(each); frequentRenterPoints ++; if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE)&& each.getDaysRented() > 1) frequentRenterPoints++; result += Ò\tÓ + each.getMovie().getTitle()+ Ò\tÓ + String.valueOf(thisAmount) + Ò\nÓ; totalAmount += thisAmount; } result += ÒAmount owed is Ò+Sting.valueOf(totalAmount) + Ò\nÓ; result += ÒYou earned Ò+Sting.valueOf(frequentRenterPoints) + Òfrequent renter points\nÓ; return result;
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
389
class Customer ... public String statement() { double totalAmount = 0; int frequentRenterPoints = 0; Enumeration rentals = _rental.elements(); String result = ÒRental Record for Ò + getName() + Ò\nÓ; while (rentals.hasMoreElements()) { double thisAmount = 0; Rental each = (Rental) rentals.nextElement(); thisAmount = amountFor(each); // add frequent renter points frequentRenterPoints ++; // add bonus for a two day new release rental if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE)&& each.getDaysRented() > 1) frequentRenterPoints++; //show figures for this rental result += Ò\tÓ + each.getMovie().getTitle()+ Ò\tÓ + String.valueOf(thisAmount) + Ò\nÓ; totalAmount += thisAmount; É
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
390
class Customer ... public String statement() { double totalAmount = 0; int frequentRenterPoints = 0; Enumeration rentals = _rental.elements(); String result = ÒRental Record for Ò + getName() + Ò\nÓ; while (rentals.hasMoreElements()) { double thisAmount = 0; Rental each = (Rental) rentals.nextElement(); thisAmount = each.getCharge(); // add frequent renter points frequentRenterPoints ++; // add bonus for a two day new release rental if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE)&& each.getDaysRented() > 1) frequentRenterPoints++; //show figures for this rental result += Ò\tÓ + each.getMovie().getTitle()+ Ò\tÓ + String.valueOf(thisAmount) + Ò\nÓ; totalAmount += thisAmount;
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
420
abstract class Price { abstract int getPriceCode(); } class ChildrenPrice extends Price { int getPriceCode(){ return MOVIE.CHILDREN; } } class NewReleasePrice extends Price { int getPriceCode(){ return MOVIE.NEW_RELEASE; } } class RegularPrice extends Price { int getPriceCode(){ return MOVIE.REGULAR; } }
January 02, 2009
O b j e c t O r i e n t e d S o f t w a r e E n g i n e e r i n g
447