Created
January 13, 2022 20:31
-
-
Save UltiRequiem/7b35016d9e71307329c83e2b5d707cb3 to your computer and use it in GitHub Desktop.
The Builder patron, a pizza
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
export enum PizzaShapes { | |
square, | |
rectangular, | |
circular, | |
} | |
export type PizzaToppings = "sausage" | "mushrooms" | "cabanossi"; | |
export type PizzaFlavor = | |
| "veggie" | |
| "meat" | |
| "pepperoni" | |
| "margherita" | |
| "cheese"; | |
export interface PizzaProperties { | |
flavor?: PizzaFlavor; | |
toppings?: PizzaToppings[]; | |
shape?: PizzaShapes; | |
} | |
// deno-lint-ignore no-empty-interface | |
interface Pizza extends PizzaProperties {} | |
class Pizza { | |
constructor({ flavor, shape, toppings }: PizzaProperties = {}) { | |
this.flavor = flavor; | |
this.shape = shape; | |
this.toppings = toppings; | |
} | |
setFlavor(flavor: PizzaFlavor) { | |
this.flavor = flavor; | |
return this; | |
} | |
setShape(shape: PizzaShapes) { | |
this.shape = shape; | |
return this; | |
} | |
setToppings(toppings: PizzaToppings[]) { | |
this.toppings = toppings; | |
return this; | |
} | |
} | |
export default Pizza; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment