- Game Development Patterns and Best Practices
- John P. Doran Matt Casanova
- 129字
- 2021-07-02 23:43:41
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:

推薦閱讀
- Software Testing using Visual Studio 2012
- 從學徒到高手:汽車電路識圖、故障檢測與維修技能全圖解
- Flutter跨平臺開發入門與實戰
- Visual Basic程序設計實驗指導(第二版)
- JavaScript應用開發實踐指南
- 時空數據建模及其應用
- Elasticsearch Essentials
- TypeScript 2.x By Example
- PHP+MySQL動態網站開發從入門到精通(視頻教學版)
- 數據分析與挖掘算法:Python實戰
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術
- LabVIEW數據采集(第2版)
- 精通Oracle 12c 數據庫管理
- ServiceDesk Plus 8.x Essentials
- LabVIEW案例實戰