Refactoring for kickstarters- Lazy Class 2
Code Smell of the year
Take care of lazy subclasses too.
public abstract class Address {
private final String house;
private final String street;
private final String city;
private final String postcode;
private final String country;
public Address (String house, String street, String city,
String country, String postcode){
this.house = house;
this.street = street;
this.city = city;
this.postcode = postcode;
this.country = country;
}
public String getAddressSummary(){
return house + ", " + street + ", " + city + ", " + postcode.getPostcode() +
", " + country;
}
}
public class ShippingAddress extends Address {
public ShippingAddress(String house, String street, String city, String country, String postcode){
super(house, street, city, country, postcode);
}
public double calculatePostage(){
return country == "United Kingdom" ? 3 : 6;
}
}
You can fork it here from Github.
This is step seven of the second part of the Refactoring kickstart beginner series. Here is step 8.