-
-
Save westonal/2b91434b9d8989f52f8d071f47806f6c to your computer and use it in GitHub Desktop.
Software Design Interview Question
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
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() | |
} |
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. | |
*/ | |
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() | |
} | |
} | |
} |
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]; | |
coffeeMaker.brew(); | |
} | |
fun stringToCoffeeMaker() { | |
BaseCoffeeMaker coffeMaker = null; | |
switch (coffeeType) | |
{ | |
"drip" -> AutomaticDripCoffeeMaker() | |
} else if (coffeeType.equals("pourOver")) { | |
coffeeMaker = new PorcelainPourOverCoffeeMaker(); | |
} | |
} | |
} |
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(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