Is ArrayList an aggregation or composition?

后端 未结 2 663
时光说笑
时光说笑 2021-01-27 04:18

I am preparing for my programming exam and came across this question, I know that in aggregation the object is borrowed, and in composition the object is owned. Is the answer co

2条回答
  •  梦毁少年i
    2021-01-27 04:57

    Since Point has a real existence outside of the array, it's an aggregation.

    https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-aggregation-vs-composition/

    as stated:

    Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist.

    Composition implies a relationship where the child cannot exist independent of the parent. Example: House (parent) and Room (child). Rooms don't exist separate to a House.

提交回复
热议问题