Hotel-Management-Project-Java icon indicating copy to clipboard operation
Hotel-Management-Project-Java copied to clipboard

Food works only for a fixed amount of items

Open dsantistevan opened this issue 5 years ago • 0 comments

The Food class wouldn't be able to handle a different item that the ones listed there, and if an indefinite amount of items were added this code wouldn't be able to handle it.

Food(int itemno,int quantity)
    {
        this.itemno=itemno;
        this.quantity=quantity;
        switch(itemno)
        {
            case 1:price=quantity*50;
                break;
            case 2:price=quantity*60;
                break;
            case 3:price=quantity*70;
                break;
            case 4:price=quantity*30;
                break;
        }
    }

This is a violation to the Open Closed Principle of SOLID design, because this is not open for extension.

dsantistevan avatar Jul 13 '20 01:07 dsantistevan