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

  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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 下班总是让人欣慰的时刻,对于下班这件事情,我看的很神圣,不管下班多晚,我都一定要履行完一些程序再走。 必须将桌面整...
    DUMANMAN阅读 295评论 0 0
  • 1、她已经成了为最好的朋友,她给了我很多勇气。我祝福她接下来的人生,也同样祝福其他的朋友。只是我再也不会像过去那样...
    寻觅一路阅读 168评论 0 0