'Is it recommended to make associations to enum classes in UML class diagrams?
I am designing a class diagram and I got a doubt:
I have a class which have several attributes referring to Java enums and other classes that will be mapped as DB catalogs.
For example, there is a class called BankAccount which has an attribute called type:BankAccountType (enum)
and other which is bank:Bank (catalog class)
.
Is it recommendable to mark the association between classes or it can be obviated? If yes, should they be aggregated (a BankAccount
HAS a bankAccountType
) or simply associated?
Solution 1:[1]
Regardless of whether the attribute type is an enum, there are two ways to represent attributes in UML: as proper attributes, and as directed associations.
The two styles of attribute declarations are semantically equivalent: they mean exactly the same thing. In other words, which one you choose comes down to a matter of style.
Using attributes makes for a simpler diagram, and in some tools is required in order for the attribute to be visible in the tree view of the model.
Using directed associations means you must include the target type (the enum) in the diagram, which means you can see the literals. Of course, you can include it in the other case too, as I've done with An_Enum above.
I don't normally use aggregations or compositions for code-level modeling; I feel they're better suited for describing more abstract relationships between classes (as in an information model) and conceptually they don't really match anything in source code. Attributes do, possibly supplemented by "dependency" or "use" relationships to classes which are used as local variable types or whose methods are called.
Solution 2:[2]
A simple association would do the trick. Aggregation shows that the life cycle of the contained class is tied to the containing class.
From wikipedia: Aggregation can occur when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container—essentially, if the container is destroyed, its contents are not. http://en.wikipedia.org/wiki/Class_diagram#Aggregation
Also, found this for you: UML class diagram enum
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Uffe |
Solution 2 | Community |