I am confused about the usage of associations with Java Enums in UML Class diagrams. Currently I am modelling a system containing a Car class that has some properties. Some are also Enums, just like FuelKind or CarBrand :
There are going to be a lot of cars in the database ( Car is a JPA entity) and I'm asking myself which is the best association and cardinality to FuelKind and CarBrand .
My thoughts until now:
Do you have some suggestions and thoughts on how to solve this problem?
You're doing it almost right. A directed association is the correct relationship for this situation.
To clarify that the association refers to a specific attribute in the class, use a target role. This is displayed as a text label with the name of the attribute (fuelKind) at the enumeration end ( not the class end) of the connector.
If you had two attributes of the same enum type you would then have to draw two separate associations.
However, since you are using the type names in the attributes you don't actually need to draw any relationships at all. But if you do, a directed association with a target role is semantically equivalent to naming the type in the attribute. Which you choose is a matter of style, and you can do both if it helps clarify things.
As to a relationship going the other way, the directed nature of the association means that the relationship is one-way. In other words, drawing it the way you've done does not indicate a relationship from the enum types back to the class. And for enum types there normally shouldn't be, any more than there are such relationships for integers or strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.