I have enum CarBrand
:
public enum CarBrand {
BMW, MERCEDES, VOLKSWAGEN, AUDI, FORD, OPEL
}
and enum CarBodyType
:
public enum CarBodyType {
SEDAN, MINIVAN, VAN
}
Relationship between them is many to many. I.e. a car brand can have several variants of type of car body, and a car body type has several brands.
How to define such entity–relationship model in my code with these enums?
Maybe I need make field in each enum as a set parameterized by another enum?
public enum CarBrand {
BMW, MERCEDES, VOLKSWAGEN, AUDI, FORD, OPEL;
private Set<CarBodyType> bodyTypes;
public Set<CarBodyType> getBodyTypes() {
return bodyTypes;
}
public void setBodyTypes(Set<CarBodyType> bodyTypes) {
this.bodyTypes = bodyTypes;
}
}
and
public enum CarBodyType {
SEDAN, MINIVAN, VAN;
private Set<CarBrand> brands;
// getter and setter
}
Is this a good solution? Or would it be better to implement such relationships via a third junction entity? If so, what should it be? How should this entity be designed and what fields should it contain?