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

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:

主站蜘蛛池模板: 宜丰县| 三原县| 永平县| 包头市| 蓝田县| 昭苏县| 苍溪县| 突泉县| 胶南市| 梅州市| 高雄县| 通山县| 巴东县| 三原县| 高雄市| 合作市| 新竹县| 永嘉县| 高唐县| 陇南市| 彝良县| 桂平市| 乐至县| 巴彦淖尔市| 台东县| 郑州市| 张家界市| 泽库县| 万盛区| 乐安县| 时尚| 景洪市| 永泰县| 道孚县| 灵石县| 新建县| 城市| 长垣县| 巫山县| 澄江县| 保德县|