Skip to content

Instantly share code, notes, and snippets.

@ragmha
Created November 26, 2018 13:47
Show Gist options
  • Save ragmha/2feeec6cbae818b22a792a2cb75a6d35 to your computer and use it in GitHub Desktop.
Save ragmha/2feeec6cbae818b22a792a2cb75a6d35 to your computer and use it in GitHub Desktop.
interface SizesInterface {
availableSizes: string[];
}
abstract class Sizes implements SizesInterface {
constructor(protected sizes: string[]) {}
set availableSizes(sizes: string[]) {
this.sizes = sizes;
}
get availableSizes() {
return this.sizes;
}
}
interface PizzaInterface extends SizesInterface {
readonly name: string;
toppings: string[];
updateSizes(sizes: string[]): void;
addTopping(topping: string): void;
}
class Pizza extends Sizes implements PizzaInterface {
public toppings: string[] = [];
constructor(readonly name: string, sizes: string[]) {
super(sizes);
}
public updateSizes(sizes: string[]) {
this.sizes = sizes;
}
public addTopping(topping: string) {
this.toppings.push(topping);
}
}
const pizza = new Pizza("Puuporrroni", ["small", "medium"]);
console.log(pizza.availableSizes);
pizza.updateSizes(["large", "ultimate"]);
console.log(pizza.availableSizes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment