Created
March 28, 2011 23:18
-
-
Save anonymous/891525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THE BAD | |
public class Lamp | |
{ | |
private int bulbAge; | |
private String bulbType; | |
private int shadeAge; | |
public Lamp(int bulbAge, String bulbType, int shadeAge) | |
{ | |
this.bulbAge = bulbAge; | |
this.bulbType = bulbType; | |
this.shadeAge = shadeAge; | |
} | |
public boolean needsMaintainance() | |
{ | |
if(bulbType.equals("INCANDESCENT")) | |
return bulbAge > 2; | |
else if(bulbType.equals("HALOGEN")) | |
return bulbAge > 5; | |
return false; | |
} | |
} | |
// THE BETTER | |
public class Lamp | |
{ | |
private Bulb bulb; | |
private Shade shade; | |
public Lamp(Bulb bulb, Shade shade) | |
{ | |
this.bulb = bulb; | |
this.shade = shade; | |
} | |
public boolean needsMaintainence() | |
{ | |
return bulb.needsMaintainence(); | |
} | |
} | |
public abstract class Bulb | |
{ | |
private int age; | |
public Bulb(int age) | |
{ | |
this.age = age; | |
} | |
public boolean needsMaintainence() | |
{ | |
return age > getMaxAge(); | |
} | |
public abstract int getMaxAge(); | |
} | |
public class IncandescentBulb extends Bulb | |
{ | |
public IncandescentBulb(int age) | |
{ | |
super(age); | |
} | |
@Override | |
public int getMaxAge() | |
{ | |
return 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment