如何在 UML 中表示 Map 类成员?
当我有一个带有 Map 成员的类时,我不想绘制一个单独的类/接口对象来表示 Map 本身,但我更愿意将映射视为本机类型,而不是复杂的类型目的。
考虑以下示例,
public class IndexManagerImpl implements IndexManager {
/* ... */
private static Map<Searcher, Integer> searcherCache;
}
我想强调这样一个事实:IndexManagerImpl
保存(尽管间接)对 Searcher
实例的引用。 如果该表示形式还可以显示 searcherCache
的类型参数,那就太好了。
When I have a class with a Map member, I don't want to draw a separate class/interface object to represent the Map itself, but I'd prefer to treat the map as if it was a native type, rather than a complex object.
Consider the following example
public class IndexManagerImpl implements IndexManager {
/* ... */
private static Map<Searcher, Integer> searcherCache;
}
I'd like to highlight the fact that an IndexManagerImpl
holds (although indirectly) references to Searcher
instances.
It would be great if the representation could also show the type parameters of searcherCache
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不同意马丁的观点……MAP是我们在任何计算机毕业课程中学习的基本数据结构!它存在于大多数现代语言中,是分析师的重要设计资源。在某些情况下,地图可能会被绘制为关联,但需要某种扩展(构造型),或者您可以定义一个模板类。我不喜欢模板方法 - 它隐藏了主要参与者之间的关联。
最后一个资源是 AssociationClass,一个特殊的 UML 类,用于定义与属性的 nxn 关系,我认为适合您的问题,其中“整数”字段是与 indexManager 相关的搜索者的某种计数器。
还请记住,通过代码您无法看到关系的另一方,而 UML 旨在显示双方、导航问题等。
A disagree with Martin... MAP is basic data structure that we learn in any computer graduation course! It exsists in most modern languages and is an important design resource for analysts. A Map may be drawn as an association in some situations, but some kind of extension (stereotypes) will be needed OR you can define a template class. I don't like the template approach - it hides the associations btw the major players.
The last resource is the AssociationClass, a special UML class used to define nxn relations with attributes, what I think suits your problem, where the "integer" field is some kind of counter of Searchers related to the indexManager.
Remember also that by code you can't see the other side of the relationship, while UML is designed to show both sides, navigation issues and so forth.
实际上集合对象表示两个类之间的一对多关联。
因此,您的图表上应该有一个 IndexManagerImpl 类,它与 Searcher 类具有一对多关联
Actually collection objects indicate a one-to-many association between two classes.
Therefore you should have a IndexManagerImpl class on your diagram that has a one-to-many association with a Searcher class
地图不能被视为集合,因为它们具有与集合不同的属性。实际上,映射是具有特定(映射)关系的集合的多个。在我看来,地图的表示高度依赖于需求,并且根据您的需求可能有多种地图 UML 表示形式。
因此,可以以简单的形式表示映射关系,即与键集元素的一对多关联以及键集元素与值元素的一对一关联。
其中键元素和值元素是原始元素的包装,因为关联实际上并不与原始元素相关。
希望这有帮助......
Maps cannot be considered collections as they have different properties than collections. Actually a map is multiple of collection with specific (mapping) relationship. In my view representing map is highly dependent on the requirement and there could be several map UML representation based on your requirement.
Thus in a simple form map relationship can be represented, one to many association to key set element and one to one association of keyset element to value element.
Where key element and value element are wrappers to original elements as association are not actually with the original elements.
Hope this helps....