UML 中的组合 [英] Composition in UML
问题描述
在考虑组合时在 UML 图中.我们应该在逻辑或实现意义上使用它.两个术语的示例:
In UML diagrams when considering composition. Should we use it in logical or implementation sense. Examples for both terms:
- 实施 - 机场将包含对国家/地区的引用.换句话说,一个国家是机场的一部分.
- 逻辑 - 一个国家可以有零个或多个机场.换言之,机场是国家的一部分.
从上图中,哪种情况显示了组合的正确用法?注意:如果这两种情况都不好,请提出其他方式来表示国家和机场之间的关系.
From diagram above, which case shows correct usage of composition? NOTE: if neither of these cases are good, please suggest other ways to show relationship between country and airport.
推荐答案
我认为这不是一个具有强烈UML 意义"的词.
I think that this is not a composition in the strong "UML sense" of that word.
来自维基百科:
组合和组件之间的关系是一种很强的has a"关系,因为组合对象获得了组件的所有权.这意味着组合负责组件部分的创建和销毁.
机场不会创建国家(在 IT 意义上,国家"对象也不负责提供/创建机场"对象).
An Airport does not create countries (and in IT sense, a "country" object is also not responsible for providing/creating "airport" objects).
从这个意义上说,您希望在这里建立关联;我认为第一个更合适(用一般"说话).但核心方面是:你的模型必须表达你领域的具体需求.换句话说:两个解决方案都是有效的;这在很大程度上取决于选择哪一个的上下文.换句话说:您选择一个可以帮助您解决问题的方法!
In that sense, you are looking towards an association here; and I think the first one fits better (talking in "general"). But the core aspect is: your model has to express the specific requirements of your domain. In other words: both solutions are valid; it very much depends on the context which one to choose. In other words: you pick the one that helps you solving your problem!
这篇关于UML 中的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!