UML class diagram enum

后端 未结 3 1726
难免孤独
难免孤独 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 <> Stereotype, but in the UML metamodel, an Enumeration is actually a separate (meta)type.

    +---------------------+
    |   <>   |
    |    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

提交回复
热议问题