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

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:

主站蜘蛛池模板: 容城县| 太仆寺旗| 驻马店市| 中阳县| 同心县| 教育| 陵川县| 木里| 漾濞| 云南省| 浑源县| 沽源县| 白沙| 寻甸| 阿勒泰市| 会宁县| 融水| 洞口县| 长汀县| 常宁市| 射洪县| 黄冈市| 乌拉特中旗| 苏尼特左旗| 镇康县| 屯昌县| 鄂尔多斯市| 噶尔县| 浦城县| 岫岩| 陕西省| 松江区| 城口县| 长汀县| 白玉县| 荥阳市| 中卫市| 仙居县| 韩城市| 大宁县| 龙岩市|