Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save westonal/2b91434b9d8989f52f8d071f47806f6c to your computer and use it in GitHub Desktop.
Save westonal/2b91434b9d8989f52f8d071f47806f6c to your computer and use it in GitHub Desktop.
Software Design Interview Question
class AutomaticDripCoffeeMaker(inner: CoffeeMaker) : CoffeeMaker {
public Heater heater;
public Pump pump;
public AutomaticDropCoffeeMaker() {
super();
}
public void scheduleBrew() {
// schedules a call to #brew()
}
fun brew() {
if(
}
}
interface CoffeeMaker {
fun brew()
}
/**
* Base class for a coffee maker.
*/
class AutomaticDripCoffeeMaker(inner: CoffeeMaker) : CoffeeMaker {
public Heater heater;
public Pump pump;
public BaseCoffeeMaker() {
heater = new ElectricHeater();
pump = new ThermosiphonPump();
}
public Heater getHeater() {
return heater;
}
public Pump getPump() {
return pump;
}
override brew() {
if (heater.isAtBrewTemp()) {
inner.brew()
}
}
}
public class CoffeeShop {
public static void main(String[] args) {
String coffeeType = args[0];
coffeeMaker.brew();
}
fun stringToCoffeeMaker() {
BaseCoffeeMaker coffeMaker = null;
switch (coffeeType)
{
"drip" -> AutomaticDripCoffeeMaker()
} else if (coffeeType.equals("pourOver")) {
coffeeMaker = new PorcelainPourOverCoffeeMaker();
}
}
}
public class PorcelainPourOverCoffeeMaker(inner: CoffeeBrewer) : CoffeeBrewer by inner {
public PorcelainPourOverCoffeeMaker() {
super();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment