I was reading a post Inheritance and Composition (Is-a vs Has-a relationship) in Java and I ambit confused by what this following statement.
It's also worth noting that in this case, the containing Computer object has ownership of the contained objects if and only if the objects can't be reused within another Computer object. If they can, we'd be using aggregation, rather than composition, where ownership isn't implied.
Here is the code snippet being referenced
public class Computer{
private Processor processor;
private Memory memory;
private SoundCard soundCard;
//... more code
}
What does it mean by being reused within another Computer object? Does it mean that when I have two instantiations of Computer that they shouldn't be sharing those composed objects (processor, memory, soundcard)?
Can someone give an example where aggregation is used instead of composition following the statement above?
Aucun commentaire:
Enregistrer un commentaire