Last active
May 22, 2018 16:23
-
-
Save arriolac/6ec286a5d5add9efc50a to your computer and use it in GitHub Desktop.
This file contains 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
public class AutomaticDripCoffeeMaker extends BaseCoffeeMaker { | |
public AutomaticDropCoffeeMaker() { | |
super(); | |
} | |
public void scheduleBrew() { | |
// schedules a call to #brew() | |
} | |
} |
This file contains 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
/** | |
* Base class for a coffee maker. | |
*/ | |
public class BaseCoffeeMaker { | |
public Heater heater; | |
public Pump pump; | |
public BaseCoffeeMaker() { | |
heater = new ElectricHeater(); | |
pump = new ThermosiphonPump(); | |
} | |
public Heater getHeater() { | |
return heater; | |
} | |
public Pump getPump() { | |
return pump; | |
} | |
public void brew() { | |
if (heater.isAtBrewTemp()) { | |
//brew | |
} | |
} | |
} |
This file contains 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
public class CoffeeShop { | |
public static void main(String[] args) { | |
String coffeeType = args[0]; | |
BaseCoffeeMaker coffeMaker = null; | |
if (coffeeType.equals("drip")) { | |
coffeeMaker = new AutomaticDripCoffeeMaker(); | |
} else if (coffeeType.equals("pourOver")) { | |
coffeeMaker = new PorcelainPourOverCoffeeMaker(); | |
} | |
coffeeMaker.brew(); | |
} | |
} |
This file contains 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
public class PorcelainPourOverCoffeeMaker extends BaseCoffeeMaker { | |
public PorcelainPourOverCoffeeMaker() { | |
super(); | |
heater = null; | |
pump = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment