关于relationship的疑惑:dependency和association以及aggregation有何区别?
四种relationship在Java代码上都有什么区别?
dependency,association,aggregation,combination
dependency是对对象的只读引用吗?
dependency和association在代码中有什么区别?
association和aggregation到底在代码中有什么区别?
combination是子对象在父对象的constructor中实例化的吗??
请看如下代码,并告诉我都是哪种relationship,谢谢!!
class B{
public int i=0;
}
class A{
private B b1;
private B b2;
private B b3;
private B b5 = new B();//association?
private int n=0;
public A(){
b1 = new B();//combination?
}
void addItem(B f){
n=f.i; //dependency?
}
void changeItem(B c){
B b4 = c;//association?
b4.i++;//c is changed
}
void setList(B e){
b2 = e.clone();//aggregation?
}
void initialize(){
b3 = new B();//what relationship?
}
}