Hi guys!
I'd like to talk about DI in game engine architecture. Main question is should this technique be used or not?
Basically everything breaks down to the choice:
This is it. What do you guys think? How all those global services (i.e. logger, process manager, event manager, renderer etc etc) should be organized? What's used in the serious industry? Share your thoughts!
I'd like to talk about DI in game engine architecture. Main question is should this technique be used or not?
Basically everything breaks down to the choice:
- Exposing game services as singletons and then access them inside various classes. (I don't distinguish here between global or OOP singleton as they basically the same.)
pros
- only singleton header is included
- works fast
- pretty well-known pattern
cons
- tightly coupled code
- hidden dependencies between classes
- google says that it's hard to do unit testing with it
- seems like people are abandoning this concept lately
- Exposing services as service locator pattern.
Same as the singleton except that game services are abstracted away and hidden into the container and we query the container instead of asking each service for its singleton. (Seems like this requires singleton of the locator though.) Sounds like more robust but slower solution.
- Using construction dependency injection to pass the services interfaces everywhere we need them.
pros
- code isn't coupled anymore
- best flexibility and portability
- explicit dependency in the class constructor definition
cons
- alot harder to prototype (requires much more time)
- now constructors are bloated with interfaces (maybe there's a solution to this?)
- harder to read for those who don't like fancy pattern thing
This is it. What do you guys think? How all those global services (i.e. logger, process manager, event manager, renderer etc etc) should be organized? What's used in the serious industry? Share your thoughts!
Looking for a job!
My LinkedIn Profile
My LinkedIn Profile