| Замена условной логики на полиморфизм | Страница 37 |
class Rental...
public int getFrequentRenterPoints() {
return movie.getFrequentRenterPoints( daysRented);
}
class Movie...
public int getFrequentRenterPoints( int daysRented) {
if( getPriceCode()==NEW_RELEASE && daysRented()>1)
return 2;
else
return 1;
}
Рис 1.13 Диаграмма классов после переноса метода в классMovie
Оглавление | << страница 36 | страница 38 >>