A question about hierarchy
I'm trying write a game and I'm deciding how to set up my classes.
The main class will be gameManager, which will be the class that is in control of all decision making and execution. It will have members like displayManager, which will update the screen, inputManager, which will include a mouse listener and keybindings, etc.
My question is about how to make the member classes of gameManager send information to gameManager. For example if inputManager detects a click, I want to call a function in gameManager to actually send it the input and it let it decide what to do from there.
So how do I call a function in gameManager from inputManager, if my instance of inputManager is a member of gameManager? My first thought was to actually give every class that needs to communicate with gameManager a gameManager field. So I'd call the constructor for inputManager with an instance gameManager, so it could know about gameMangager and call its functions that way. I have a bad feeling about that though, like maybe it's too complicated or I'm breaking some rule of good programming that I don't know about. Any advice on how to do this?
Re: A question about hierarchy
InputManager will have a way of registering an InputListener.
It'll hold a List of these Listeners.
The InputListener interface will have whatever methods you think it needs to have to allow the InputManager to inform a Listener that something has happened it needs to act upon.
GameManager will implement InputListener, and register itself with the InputManager.
This should allow you to, later on, should you decide the GameManager is too large, to move the responsibility of listening in on the InputManager to something else, without having to change the Inputmanager.