组合 聚合 区别

组合关系(强拥有关系,生命周期相同,如鸟和翅膀)

public class TestOne {

}

public class TestTwo {
	private TestOne test1;
	public TestTwo() {
		// TODO Auto-generated constructor stub
		 test1 = new TestOne();
	}
}

 

 

聚合关系(弱拥有关系,如公司和员工,员工可以离开公司)

public class TestOne {

}

public class TestTwo {
	private TestOne test1;
}

简单理解,TestTwo类用到了TestOne类的实例。

posted @ 2013-05-15 22:09  helloweworld  阅读(150)  评论(0编辑  收藏  举报