How to describe a contained map in UML class diagram?

前端 未结 6 1793
迷失自我
迷失自我 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条回答
  •  悲&欢浪女
    2020-12-01 16:21

    Kru's answer is the best, but it still only hints at a Map.

    I would argue it depends on the level of abstraction at which your diagram sits. If it's relatively high, I'd go with chimp's response. If it's relatively low and you really need to show a map, intentionally showing implementation-related detail, I'd go with the following:

               MyServer
                   |
                   |
                  Map                
                   |
                   |*
                T1toT2
                /    \
              1/      \1
             Key     Value
    

    How the map is then implemented in code is totally irrelevant (T1toT2 run-time objects might not actually come to be).

    As mentioned by Gabreil, this could be also be modelled using an association class

               MyServer
                   |
                   |
                  Map                
                   |
                   |*
                T1toT2
                   |
                   |
              1--------1
             Key     Value
    

    Of course is only matters if you really really need to show or specify a map.

提交回复
热议问题