美文网首页
10 探索类与类之间的关系(未完待续)

10 探索类与类之间的关系(未完待续)

作者: Closears | 来源:发表于2017-11-08 22:43 被阅读5次
    1. Object Composition (可细分为CompositionAggregation两部分),
      "it allows us to create complex classes by combining simpler, more easily manageable parts."
      1.1 Composition与Aggregation的共同点
      The part (member) is part of the object (class) . - part-whole relationship
      The part (member) does not know about the existence of the object (class).- unidirectional relationship
      1.2 Composition与Aggregation的区别

    Composition:

    1. Parts can belong to only one object at a time.
    1. The whole object is responsible for the existence and lifespan of the parts.
    1. It models "part-of" relationships.
    1. In a composition, we typically add our parts to the composition using normal member variables (or pointers where the allocation and deallocation process is handled by the composition class).

    Aggregation:

    1. Parts can belong to more than one object at a time.
    1. The whole object is not responsible for the existence and lifespan of the parts.
    1. It models "has-a" relationships.
    1. In an aggregation, we also add parts as member variables. However, these member variables are typically either references or pointers that are used to point at objects that have been created outside the scope of the class.
    1. TBD

    相关文章

      网友评论

          本文标题:10 探索类与类之间的关系(未完待续)

          本文链接:https://www.haomeiwen.com/subject/ivcumxtx.html