How to describe a contained map in UML class diagram?

前端 未结 6 1783
迷失自我
迷失自我 2020-12-01 16:10

I have a MyServer class that contains a Map whose keys are MyClientType objects and whose values are MyClient objects. I\'d like to depict this relationship in a class diagr

6条回答
  •  -上瘾入骨i
    2020-12-01 16:45

    You can use a qualified association:

    ┌──────────┐             1 ┌───────┐
    │ MyServer │Key│───────────│ Value │
    └──────────┘               └───────┘
    

    See: http://etutorials.org/Programming/UML/Chapter+6.+Class+Diagrams+Advanced+Concepts/Qualified+Associations/ (cause it is hard to draw using ASCII)

    Note also that a qualified association changes the multiplicity:

    ┌──────────┐          0..* ┌───────┐
    │ MyServer │───────────────│ Value │
    └──────────┘               └───────┘
    
    ┌──────────┐             1 ┌───────┐
    │ MyServer │Key│───────────│ Value │
    └──────────┘               └───────┘
    

    The top illustrates an association from a server to 0-n values. By contrast, the qualified association says that any given key will be associated with only one value, and that you can't have a key an absent value.

提交回复
热议问题