is it recommended to make associations to enum classes in uml class diagram?

htafoya picture htafoya · Sep 15, 2011 · Viewed 36.8k times · Source

I am designing a class diagram and I got a doubt:

I have a class which have several attributes refering 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?

Thank you in advance.

Answer

Uffe picture Uffe · Sep 15, 2011

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 ways of representing attributes in UML

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.