• Association, Composition, Aggregation(转)


    Association, Aggregation and Composition

    Source: comp.object
    Date: 10-Jun-98

    Related Sites


    ------------------------------

    o-< Problem: UML has several relations (association, aggregation and composition) that seem to all mean the same thing : "has a".
    So, what is the difference between them?


    ---------------

    o-< Robert C. Martin explained:

    Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.

    [Example:]

    |A|----------->|B|
    class A
    {
    private:
    B* itsB;
    };
    Aggregation [...] is the typical whole/part relationship. This is exactly the same as an association with the exception that instances cannot have cyclic aggregation relationships (i.e. a part cannot contain its whole).

    [Example:]

    |Node|<>-------->|Node|
    class Node
    {
    private:
    vector<Node*> itsNodes;
    };
    The fact that this is aggregation means that the instances of Node cannot form a cycle. Thus, this is a Tree of Nodes not a graph of Nodes.

    Composition [...] is exactly like Aggregation except that the lifetime of the 'part' is controlled by the 'whole'. This control may be direct or transitive. That is, the 'whole' may take direct responsibility for creating or destroying the 'part', or it may accept an already created part, and later pass it on to some other whole that assumes responsibility for it.

    [Example:]

    |Car|<#>-------->|Carburetor|
    class Car
    {
    public:
    virtual ~Car() {delete itsCarb;}
    private:
    Carburetor* itsCarb
    };
  • 相关阅读:
    水晶报表显示到aspx页面中
    Python 2.7获取网站源代码的几种方式_20160924
    Seal Report_20160923
    MySQL交叉表处理_20160923
    MySQL日期处理函数_20160922
    MySQL文本处理函数2_20160921
    kettle及数据库导数_20160920
    MySQL常用的数据类型及函数_20160920
    MySQL记录_20160919
    [vuex]
  • 原文地址:https://www.cnblogs.com/cloudseawang/p/1268395.html
Copyright © 2020-2023  润新知