The terms “composition” and “aggregation” mean more or less the same thing and can be used interchangeably. Aggregation can be used more often when describing container classes, such as lists, dynamic arrays, maps, and queues, where all elements are of the same type; however, both terms can be found to describe classes defined in terms of other classes, regardless of whether these types are homogeneous (all of the same type) or heterogeneous (objects of different types).
To make this clear:
class Car {
private:
Engine engine;
Hood hood;
};
, /; , , . , , / ( , , / , ), ( , ).
:
interface Car {
public Engine getEngine();
public Hood getHood();
public void drive();
}
class HondaCivic2010 implements Car {
public void drive(){ getEngine().drive(); }
}
"", , , , , . , ... , - :
class GoodCharacter;
class BadCharacter;
class Mage;
class Rogue;
class GoodMage : public GoodCharacter, Mage;
class BadMage : public BadCharacter, Mage;
class GoodRogue : public GoodCharacter, Rogue;
class BadRogue : public BadCharacter, Rogue;
, , . , , :
class Personality;
class GoodPersonality : public Personality;
class BadPersonality : public Personality;
class CharacterClass;
class Mage : public CharacterClass;
class Rogue : public CharacterClass;
class Character {
public:
private:
CharacterClass character_class;
Personality personality;
};