Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternative to deeply nested function calls or events
    primarykey
    data
    text
    <p>I have repeatedly come across this problem in multiple projects: I end up with objects (nested deep down in a structure) that need to communicate with objects external to that structure. </p> <p>Currently I have the Game class which instantiates the Hud and ObjectsList classes.<br> The Hud instantiates the various heads up display panels, which themselves instantiate smaller sections containing the visible TextFields.<br> The ObjectsList instantiates the various game objects, including the Player class.<br> For the Player to communicate to a specific Hud panel I currently need to trigger a sequence of custom events all the way up to Game, then have game call a method on Hud, which calls the method on the appropriate Hud panel.<br> Ths seems rather clunky and inefficient. I could pass Player a reference to the Hud as it could be said that Player 'has-as' Hud. But is that tight coupling? And, given that I'm not expecting to have to reuse this code elsewhere, does that matter?<br> I could also use the Observer Pattern and register Hud panels to listen for updates from Player, but then, when both Player and hud panel are not immediately accessible to Game, where does this get managed?<br> Or should all of the instantiations happen in Game and then the structure 'composed'? </p> <p>I am keen to know if there is something I don't understand that makes these seemingly clunky, nested structures occur, or if they are just a necessary byproduct.<br> And if there is anything fundamentally wrong with the structure I've suggested, I'd appreciate knowing what the practical alternatives are (preferably in un-jargoned language as I am a self taught coder).<br> Cheers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload