ACM - Computers in Entertainment

Smart composition of game objects using dependency injection

By Erick B. Passos, Jonhnny Weslley S. Sousa, Esteban Walter Gonzales Clua, Anselmo Montenegro, Leonardo Murta
SPECIAL ISSUE: Games, [Vol. 7, No. 4]

DOI: 10.1145/1658866.1658872

Most game engines are based on inheritance of game objects and/or componentization of behaviors. While this approach enables clear visualization of the system architecture, good code reuse, and fast prototyping, it brings some issues, mostly related to the high dependency between game objects/components instances. This dependency often leads to static casts and null pointer references that are difficult to debug. In this article we propose the use of the dependency injection design pattern to safely initialize game objects and lessen the programmer's role in handling these issues both during the prototyping and production phases. Since these dependencies are attributes of game objects and the injection occurs only at the initialization pass, there is no performance penalty at the game loop.

Copyright © 2019. All Rights Reserved

Full text is available in the ACM Digital Library