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

推薦閱讀
- Oracle 11g從入門(mén)到精通(第2版) (軟件開(kāi)發(fā)視頻大講堂)
- PHP 7底層設(shè)計(jì)與源碼實(shí)現(xiàn)
- Hadoop+Spark大數(shù)據(jù)分析實(shí)戰(zhàn)
- 重學(xué)Java設(shè)計(jì)模式
- Learning Apache Mahout Classification
- Visual C++開(kāi)發(fā)入行真功夫
- 劍指大數(shù)據(jù):企業(yè)級(jí)數(shù)據(jù)倉(cāng)庫(kù)項(xiàng)目實(shí)戰(zhàn)(在線教育版)
- 打開(kāi)Go語(yǔ)言之門(mén):入門(mén)、實(shí)戰(zhàn)與進(jìn)階
- Spring 5 Design Patterns
- Everyday Data Structures
- 微課學(xué)人工智能Python編程
- ASP.NET求職寶典
- 貫通Tomcat開(kāi)發(fā)
- Building Clouds with Windows Azure Pack
- Oracle 11g寶典