UML class diagram enum

后端 未结 3 1716
难免孤独
难免孤独 2020-12-02 06:15

I am modeling a class diagram. An attribute of a class is an enumeration. How do I model this? Normally you do something like this:

- name : string


        
相关标签:
3条回答
  • 2020-12-02 06:49

    If your UML modeling tool has support for specifying an Enumeration, you should use that. It will likely be easier to do and it will give your model stronger semantics. Visually the result will be very similar to a Class with an <<enumeration>> Stereotype, but in the UML metamodel, an Enumeration is actually a separate (meta)type.

    +---------------------+
    |   <<enumeration>>   |
    |    DayOfTheWeek     |
    |_____________________|
    | Sunday              |
    | Monday              |
    | Tuesday             |
    | ...                 |
    +---------------------+
    

    Once it is defined, you can use it as the type of an Attribute just like you would a Datatype or the name one of your own Classes.

    +---------------------+
    |        Event        |
    |_____________________|
    | day : DayOfTheWeek  |
    | ...                 |
    +---------------------+
    

    If you're using ArgoEclipse or ArgoUML, there's a pulldown menu on the toolbar which selects among Datatype, Enumeration, Signal, etc that will allow you to create your own Enumerations. The compartment that normally contains Attributes can then be populated with EnumerationLiterals for the values of your enumeration.

    Here's a picture of a slightly different example in ArgoUML: enter image description here

    0 讨论(0)
  • 2020-12-02 06:50

    Typically you model the enum itself as a class with the enum stereotype

    0 讨论(0)
  • 2020-12-02 07:03

    They are simply showed like this:

    _______________________
    |   <<enumeration>>   |
    |    DaysOfTheWeek    |
    |_____________________|
    | Sunday              |
    | Monday              |
    | Tuesday             |
    | ...                 |
    |_____________________|
    

    And then just have an association between that and your class.

    0 讨论(0)
提交回复
热议问题