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?
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:
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
}
}
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
.