- 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:

推薦閱讀
- Learning Single:page Web Application Development
- Mastering Entity Framework
- Learning Neo4j 3.x(Second Edition)
- Quarkus實(shí)踐指南:構(gòu)建新一代的Kubernetes原生Java微服務(wù)
- Learning Network Forensics
- Bootstrap 4:Responsive Web Design
- Access 2016數(shù)據(jù)庫(kù)管
- 零基礎(chǔ)入門學(xué)習(xí)Python(第2版)
- C語(yǔ)言程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo) (第2版)
- PHP編程基礎(chǔ)與實(shí)例教程
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- Microsoft Dynamics AX 2012 R3 Financial Management
- C#程序設(shè)計(jì)(項(xiàng)目教學(xué)版)
- Angular Design Patterns
- Spark技術(shù)內(nèi)幕:深入解析Spark內(nèi)核架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)原理