I am designing a Menu system for a restaurent in Typescript. I have defined an interface to implement necessary function for each Menu Item :
interface HasPrice {
getPrice(): number;
}
Each menu item is defined by a class.
class Gobi implements HasPrice {
getPrice() : number {
return 50;
}
}
class FriedRice implements HasPrice {
getPrice() : number {
return 100;
}
}
I am using decorator class to add toppings. eg.Fried Rice with chicken
class FriedRiceWithChicken implements HasPrice {
getPrice() : number {
return super.getPrice() + 25;
}
}
Now I want to extend this system for combo menus. eg. Fried Rice + Gobi
class FriedRiceAndGobi extends FriedRice, Gobi {
getPrice() : number {
return FriedRice.getPrice() + Gobi.getPrice();
}
}
How can I implement combo classes? Is there a way I can write a generic class/method to implement combo menu?