Created
June 6, 2020 16:56
-
-
Save DoRightt/486bf35e231298a5bc78411260d48ef7 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
class Pizza { | |
bake() {} | |
prepare() {} | |
box() {} | |
cut() {} | |
} | |
class CheesePizza extends Pizza {} | |
class PepperoniPizza extends Pizza {} | |
class ClamPizza extends Pizza {} | |
class VeggiePizza extends Pizza {} | |
class SimplePizzaFactory { | |
createPizza(type: string): Pizza { | |
let pizza: Pizza = null; | |
if (type === "cheese") { | |
pizza = new CheesePizza(); | |
} else if (type === "pepperoni") { | |
pizza = new PepperoniPizza(); | |
} else if (type === "clam") { | |
pizza = new ClamPizza(); | |
} else if (type === "veggie") { | |
pizza = new VeggiePizza(); | |
} | |
return pizza; | |
} | |
} | |
class PizzaStore { | |
factory: SimplePizzaFactory; | |
constructor(factory: SimplePizzaFactory) { | |
this.factory = factory; | |
} | |
orderPizza(type: string): Pizza { | |
const pizza: Pizza = this.factory.createPizza(type); | |
pizza.prepare(); | |
pizza.bake(); | |
pizza.cut(); | |
pizza.box(); | |
return pizza; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment