mardi 29 décembre 2015

"managed" depends on "manager" structure

I have a structure problem with DependancyInject.

Situation

I'm working on creating a server for a voxel based game; it's entirely modulated, but the relevant modules are the following 3.

NetworkModule(sends and receives packets) WorldModule(Handles world related events and stores worlds) World(Stores all the blocks and has a list of players in the world) Block(Has a material, and some other fields)

Problem

When the setMaterial(Material material) method is called in the Block class, a "BlockChange" packet should be sent to all the players in the world to let the client know that the block has changed type. To send that packet, the Block class must have access to the NetworkModule. There is an instance of NetworkModule stored inside the WorldModule. Technically this can be easily solved, just pass the WorldModule, or NetworkModule into each Block class. To me that rings alarm bells, it ties the manager to the managed and also wastes space saving that instance. I feel like there must be a better way to do this such that they don't depend on each other.

Aucun commentaire:

Enregistrer un commentaire