This is object-oriented programming and UML terminology, not Java-specific. There are actually three cases you should be aware of:
- A House is a Building (inheritance);
- A House has a Room (composition);
- A House has an occupant (aggregation).
The difference between (2) and (3) is subtle yet important to differentiate. Together they are forms of association. What's the difference? Composition implies the child object cannot live out of the context of the parent (destroy the house and rooms disappear) whereas aggregation implies the child can exist on its own (destroy the house and the occupant goes elsewhere).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…