Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IS Relation in Java [closed]

I want to write a pizza shop where you can order pizza and pasta. This graph shows how I'm thinking of modeling it, but I don't know how to implement the IS relation between dish and pizza/pasta. Any tips on that or anything at all?

entity-relationship-modell

like image 959
ZenBa2 Avatar asked Nov 27 '25 14:11

ZenBa2


1 Answers

Dish will be an abstract class as Kayaman said:

public abstract class Dish {
    private Long id;
    private String name;
    private Double price;
    
    //Getters & Setters
}

Note that I added the id property because I agree with Vled:

Looks very good, I would add an ID for each Dish as well , if for a example a customer wants to report on a specific dish he ate.

So, Pizza and Pasta will extend it:

Pizza

public class Pizza extends Dish {
    private Topping toppings;
    private Sauce sauce;
    private Size size;

    public enum Topping {
        // Topping options
    }

    public enum Sauce {
        // Sauce options
    }

    public enum Size {
        // Size options
    }
}

Pasta

public class Pasta extends Dish {
    private Topping toppings;
    private Sauce sauce;
    private Type type;

    public enum Topping {
        // Topping options
    }

    public enum Sauce {
        // Sauce options
    }

    public enum Type {
        // Type options
    }
}

I put the properties as enums because they will be options that will compose the Dish.

like image 116
Diego Borba Avatar answered Nov 30 '25 04:11

Diego Borba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!