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

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:

主站蜘蛛池模板: 霍林郭勒市| 晋江市| 英超| 运城市| 昭觉县| 农安县| 青浦区| 长治市| 南华县| 嘉兴市| 泸定县| 大荔县| 乡宁县| 赤峰市| 泰顺县| 金乡县| 秦皇岛市| 全椒县| 金寨县| 古田县| 连江县| 阿鲁科尔沁旗| 新宁县| 烟台市| 瑞昌市| 额济纳旗| 盐池县| 成都市| 赤峰市| 黎城县| 民乐县| 华池县| 夹江县| 鸡东县| 黄龙县| 金溪县| 敖汉旗| 沂源县| 报价| 遂平县| 长汀县|