Skip to content

Instantly share code, notes, and snippets.

@arriolac
Last active May 22, 2018 16:23
Show Gist options
  • Save arriolac/6ec286a5d5add9efc50a to your computer and use it in GitHub Desktop.
Save arriolac/6ec286a5d5add9efc50a to your computer and use it in GitHub Desktop.
public class AutomaticDripCoffeeMaker extends BaseCoffeeMaker {
public AutomaticDropCoffeeMaker() {
super();
}
public void scheduleBrew() {
// schedules a call to #brew()
}
}
/**
* 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
}
}
}
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();
}
}
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