Results 1 to 2 of 2
Thread: A question about hierarchy
- 09-05-2012, 05:33 PM #1Member
- Join Date
- Sep 2012
- Rep Power
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?
- 09-05-2012, 06:38 PM #2Moderator
- Join Date
- Apr 2009
- Rep Power
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.Please do not ask for code as refusal often offends.
- By IAmACodingNoob in forum New To JavaReplies: 3Last Post: 04-06-2012, 01:55 AM
- By klz215 in forum New To JavaReplies: 2Last Post: 02-23-2012, 09:42 PM
- By robbie.26 in forum AWT / SwingReplies: 14Last Post: 06-28-2011, 04:14 PM
- By kailash in forum Java ServletReplies: 2Last Post: 02-10-2011, 07:43 AM
- By efozdel in forum New To JavaReplies: 4Last Post: 07-23-2010, 10:49 AM