Is ArrayList an aggregation or composition?

后端 未结 2 667
时光说笑
时光说笑 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条回答
  •  遥遥无期
    2021-01-27 04:56

    From here:

    Simple rules:

    1. A "owns" B = Composition : B has no meaning or purpose in the system without A
    2. A "uses" B = Aggregation : B exists independently (conceptually) from A

    Therefore, it really depends on your model. Can the elements in the list, exist without the list. Does the elements have to be put into the list to be meaningful?

    In the case of ArrayList, I think it is an aggregation.

提交回复
热议问题