官术网_书友最值得收藏!

Aggregation

The next idea is aggregation, which is designated by the HAS-A relationship. This is when a single class contains a collection of instances of other classes that are obtained from somewhere else in your program. These are considered to have a weak HAS-A relationship as they can exist outside of the confines of the class.

In this case, I created a new class called CombatEncounter which can have an unlimited number of enemies that can be added to it. However when using aggregation, those enemies will exist before the CombatEncounter starts; and when it finishes, they will also still exist. Through code it would look something like this:

class CombatEncounter 
{
public:
void AddEnemy(Enemy* pEnemy);
private:
std::list<Enemy*> enemies;

};

Inside of UML, it would look like this:

主站蜘蛛池模板: 台山市| 瑞安市| 马公市| 安溪县| 娄底市| 玉山县| 敦煌市| 镇巴县| 北票市| 哈密市| 犍为县| 寻乌县| 博野县| 东莞市| 巴南区| 肇源县| 三江| 治多县| 邵武市| 蓝山县| 饶平县| 昌江| 宁陵县| 汕头市| 阳山县| 紫云| 枣庄市| 甘谷县| 广安市| 永定县| 同仁县| 开阳县| 富阳市| 德庆县| 外汇| 屯昌县| 彰武县| 佛山市| 东台市| 平顺县| 隆昌县|