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

41,320

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.

Share:
41,320
htafoya
Author by

htafoya

Technology officer and architect, with a solid trajectory as a mobile engineer developing apps with more than 50 million users. My main experience comes from Android and iOS apps and their whole ecosystem; this is, mobile architecture and how they interact with OS, servers, CDNs, databases, statistics, advertising, notifications, UX, design principles, security, etc. My favorite languages and experiences come from Kotlin, Swift, Java, Javascript and Web Technologies. I also have non specialized knowledge on other general technology topics; I also like to keep track on what's going on out there. If I would describe myself on StackOverflow, is that I like to investigate and test thoroughly before asking any question, thus I have a relative low accept rate or badge xp, most of my questions offer new knowledge and many times they are answered by myself after I find a working solution, if none is provided by someone else. That is, points (XP) are fun but I do not care very much for that, I'm here to help expand the knowledge of my favorite techs, to learn and overall help myself and others understand how things work and build better products. I'm glad to help when I am able to or when I find new answers to solved problems.

Updated on July 13, 2022

Comments

  • htafoya
    htafoya almost 2 years

    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.

  • sgowd
    sgowd over 5 years
    Actually you are not right. Aggregation shows that the lifecycle of the contained "class's object" is tied to the object of the class. Aggregation is not the right answer. The right answer is from @Uffe