aggregation/composition 与定向 aggregation/composition?

aggregation/composition vs directional aggregation/composition?

bouml 中 aggregation/composition 和定向 aggregation/composition 有什么区别?

定向 aggregation/composition 概念在除 bouml 以外的其他地方找不到,而 bouml 没有在其网站上解释。

注意:基于代码的解释会更好。

根据BOUML UML工具箱site的措辞,"directional"必须理解为"unidirectional"(与"bidirectional"相对):

aggregation : to define a bi-directional aggregation, the code generators will produce two attributes whose names are the roles's name. This kind of relation may considered to be a shortcut to define two (directional) aggregations.

这个 "directional" 术语指的是相关对象之间的导航可能性。为了进行比较,在 MSVC2015 中,您可以在 "Is Navigable" property of the association 中找到方向的概念。

因此,单向聚合可以是例如:

class Member { ... };  // member of a club 
class Club {
   list<Members*> members; // you can go from Club to Members but not the contrary. 
   ...
};

双向聚合应该是这样的:

class Club; 
class Member {   // member of a club 
    list<Club*> clubs;  // club to which a membershib relation exist.  
    ...
};
class Club {
   list<Members*> members; // you can go from Club to Members and now back. 
   ...
};

对于单向组合,我们可以有例如:

class Element { ... };  // Elemetn doesn't know parent (=> unidirectional)
class Object {
    vector<Element> element; // own by value for example
    ...
}; 

或者:

class Element { ... }; 
class Object {
    vector<unique_ptr<Element>> element; // ownnership by unique pointer 
    ...
}; 

双向组合可以是这样的:

class Object; 
class Element {
    Object *parent;    //  you can navigate back (Element knows about parent)
    ...
 }; 
class Object {
    vector<Element> element; // own by value for example
    ...
}; 

克里斯托夫是对的。这是否意味着 "directional" 是一个错误的选择,最好将 "directional" 替换为 "unidirectional" ?

编辑:关于记录术语的一些附加元素

来自 OMG 的 UML standard v2.5 在部分 11.5.Associations 中定义了导航原则:

Navigability means that instances participating in links at runtime (instances of an Association) can be accessed efficiently from instances at the other ends of the Association. The precise mechanism by which such efficient access is achieved is implementation specific. If an end is not navigable, access from the other ends may or may not be possible, and if it is, it might not be efficient.

以下措辞支持术语"directional":

  • "箭头表示关联将被解读为将远离箭头方向的一端与箭头指向的一端关联起来"
  • "与双向导航的关联"
  • "没有方向性意义"(20.1.4节另一种图)。

然而,在许多地方,标准明确使用 "unidirectional" 和 "bidrectional":

  • "在箭头所在的图表中 仅针对单向导航关联显示,这可能表示双向导航"
  • "这些图表 (...) 可能始终显示可导航性(通过空心箭头)或不可导航性(通过 X),仅针对单向关联 (oneWay),或者从不显示"(关于结构图的 B.3.2 节)
  • 和许多其他地方

因此,虽然 "directional" 完全有效,但术语 "unidrectional" 可能是一个更好的选择,一个更明确的选择。