I have a CarBrand enumeration:
public enum CarBrand { BMW, MERCEDES, VOLKSWAGEN, AUDI, FORD, OPEL }
and CarBodyType enumeration:
public enum CarBodyType { SEDAN, MINIVAN, VAN }
Relations between them are many for many . That is, the car brand can have several options for the type of car body, and the type of car body has several brands.
How to define such an entity-relationship model in my code with these enumerations?
Perhaps I need to create a field in each enumeration as a set parameterized by another enumeration?
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;
This is a good decision? Or would it be better to implement such a relationship through a third connection object? If so, what should it be? How should this object be designed and what fields should it contain?
François Esthète
source share