I usually forget the differences between the composition and the aggregation relationships and mix them together, so here is a memento that i will share with everyone.
- Composition : a filled diamond
- Aggregation : an unfilled diamond
The relation between a car and a carburetor is a composition because the carburetor has no use if it is out of a car.
Now more interesting is the implementation in Java of these 2 relationships :
Aggregation :
class Car {
…
}
class Tyre {
private car = new Car();
…
}
Composition :
class Carburetor {
…
}
class Car{
Carburetor carburetor = null ;
public void setCarburetor( Carburetor carburetor )
{
this.carburetor = carburetor;
}
…
}
Комментариев нет:
Отправить комментарий