ArrayList< X>聚集或组成? [英] Is ArrayList<X> an aggregation or composition?
本文介绍了ArrayList< X>聚集或组成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为编程考试做准备,并遇到了这个问题,我知道在汇总对象时是借用的,而在构成时对象是拥有的.答案组成了吗?
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 composition?
ArrayList< X>
是 X 的集合还是 X 的组成?
Is an ArrayList<X>
an aggregation of X or composition of X?
ArrayList<Point> pts = new ArrayList<Point>();
Point p = new Point(0., 0., 0.);
pts.add(p);
p.setX( 10.0 );
System.out.println(p);
System.out.println(pts.get(0));
推荐答案
来自此处:
简单规则:
- A是拥有的" B =组成:在没有A的系统中,B没有任何意义或目的.
- A使用" B =聚集:B与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?
对于 ArrayList< Point>
,我认为这是一个聚合.
In the case of ArrayList<Point>
, I think it is an aggregation.
这篇关于ArrayList< X>聚集或组成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文