Opened 3 years ago
Last modified 16 months ago
#6254 new enhancement
[PetraAI] - Use more robust dependency injection.
Reported by: | Freagarach | Owned by: | |
---|---|---|---|
Priority: | Nice to Have | Milestone: | Backlog |
Component: | AI | Keywords: | design, simple |
Cc: | Patch: |
Description
E.g. currently gameState.ai.HQ
is called by plenty of "managers". It would increase modularity of the systems if upon creation the manager would receive its commanding HQ and use that. The same can be said of e.g. plans that originate from a manager (e.g. transportPlan querying gameState.ai.HQ.navalManager
).
This way, it might be possible (for modders) to have more than one manager of a kind. And at least it is more modular.
Change History (6)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
Well, the current state is also some kind of dependency injection, since the gameState is passed along. One could even argue the current state is a more pure dependency injection. However, our current state of PetraAI is something in between, we save the config at creation but query the gameState later on.
So another approach -- which may be even more DI-like -- would be to save nothing at manager/plan creation time, but always just pass gameState and manager when calling a function. (gameState for querying the current state of affairs and the manager to get e.g. config data).
Since a manager highly depends on the HQ which instantiated it and has a persistent state, I would prefer the approach of saving the HQ on creation/init.
comment:3 by , 3 years ago
Keywords: | simple removed |
---|---|
severity: | → simple |
comment:4 by , 3 years ago
Keywords: | simple added |
---|
Sounds okay. Are there other design alternatives (Other design patterns maybe)? Dependency injection is apretty common thing.