Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Created January 13, 2022 20:31
Show Gist options
  • Save UltiRequiem/7b35016d9e71307329c83e2b5d707cb3 to your computer and use it in GitHub Desktop.
Save UltiRequiem/7b35016d9e71307329c83e2b5d707cb3 to your computer and use it in GitHub Desktop.
The Builder patron, a pizza
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