Context
I'm making a 2D game in Java.
I have this Java scheme :
| Map | ---- | BlockGrid | ---- | Block |
where Map, BlockGrid and Block are Java classes.
Here, the Map class has a BlockGrid attribute and the BlockGrid class has a Block[ ][ ] attribute storing all the blocks in the grid.
My goal
I want to be able to access methods in my Map instance from my Block class.
For example, I want to call spawnEntity(..) on the Map instance to spawn an Arrow or something.
Solutions ?
I thought about making spawnEntity(..) static but I know it is not a good practice since in order to spawn an entity, the Map need to be instanciated.
I also thought about passing my Map instance as parameter in each constructor. That way, BlockGrid and Block would have access to the instance and would be able to call methods.
My question
What is the best practice for this case ? Thank you.