如何在UML图中表示STL Map?

发布于 2024-09-18 04:24:14 字数 353 浏览 5 评论 0原文

可能的重复:
如何在 UML 类图中描述包含的映射?< /a>

我想要 UML 图中的 STL MAP 符号。

Possible Duplicate:
How to describe a contained map in UML class diagram?

I want a notation for STL MAP in UML diagram.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十六岁半 2024-09-25 04:24:14

取决于您想要建模的内容以及建模方式。我多次只是对包含映射的类的组合/聚合关系与映射存储的元素进行建模,并向该关系添加一个属性:

class MyEnclosingType {
   std::map<int,MyEnclosedType*> m_map;
};

MyEnclosingType <>-------------------------- MyEnclosedType
                         << map >>

根据您使用的工具,有些工具确实可以识别它。例如BoUML,IIRC,会自动绘制类似的东西:

MyEnclosingType <>-------------------------- MyEnclosedType
                              ^
                              |
                              | << bind Key=int >>
                              |
                             map 

我不认为它完全像那样,但在某种程度上相似。归根结底,UML 是一个供人阅读的工具,而不是供计算机使用的工具。如果您确实相信代码生成(祝您好运),那么问题是您的软件需要使用什么奇怪的构造来理解您的意图。

其他一些工具将具有 STL 或允许您添加参数化类型,您可以使用它来表示相同的代码

                                                 Key=string
                                                 Value=MyEnclosedType
MyEnclosingType <>-------------------------- map

:框,KeyValue 将由与其他参数化类型一样与 map 框重叠的不连续框表示。

我会尝试使用您选择的工具对带有地图的简单代码示例进行逆向工程,并查看该工具为您生成什么。如果您不喜欢它,请考虑一下您可以做些什么,以便利用工具的功能尽可能多地洞察问题。

Depending on what you want to model and how. I have many times just modeled the composition/aggregation relationship of the class containing the map to the map stored elements and added an attribute to the relationship:

class MyEnclosingType {
   std::map<int,MyEnclosedType*> m_map;
};

MyEnclosingType <>-------------------------- MyEnclosedType
                         << map >>

Depending on the tool you are using, some do recognize it. For example BoUML, IIRC, will automatically draw something similar to this:

MyEnclosingType <>-------------------------- MyEnclosedType
                              ^
                              |
                              | << bind Key=int >>
                              |
                             map 

I don't think it was exactly like that, but somehow similar. At the end UML is a tool for people to read, not for computers. If you do believe in code generation (good luck) then the question is what strange construct you need to use for your software to understand your intentions.

Some other tools will have the STL or allow you to add parametrized types and you can use that to represent the same code as:

                                                 Key=string
                                                 Value=MyEnclosedType
MyEnclosingType <>-------------------------- map

Where both MyEnclosingType and map would be surrounded by solid boxes, and Key and Value would be represented by a discontinuous box overlapping the map box as with other parametrized types.

I would try to reverse engineer a simple code sample with a map with your tool of choice and see what the tool generates for you. If you don't like it, just think on what you can do to actually offer as much insight to the problem as you can with what the tools enables you to.

说不完的你爱 2024-09-25 04:24:14

您可以将其视为本机数据类型。
大多数时候没有理由做其他事情。

这里没有“对”或“错”。唯一的问题是如何让团队更容易理解该架构。

You can just treat it as a native data type.
Most of the time there is no reason to do something else.

There is no 'right' or 'wrong' here. The only questions is what makes the architecture more understandable to the team.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文