Results 1 to 2 of 2
  1. #1
    Aggnavarius is offline Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default 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?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default 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.

    ** This space for rent **

Similar Threads

  1. Inheritance hierarchy question
    By IAmACodingNoob in forum New To Java
    Replies: 3
    Last Post: 04-06-2012, 12:55 AM
  2. Help with inheritance/hierarchy
    By klz215 in forum New To Java
    Replies: 2
    Last Post: 02-23-2012, 08:42 PM
  3. How to pass events up a GUI hierarchy
    By robbie.26 in forum AWT / Swing
    Replies: 14
    Last Post: 06-28-2011, 03:14 PM
  4. catching exceptions (hierarchy)
    By kailash in forum Java Servlet
    Replies: 2
    Last Post: 02-10-2011, 06:43 AM
  5. Hierarchy in Project
    By efozdel in forum New To Java
    Replies: 4
    Last Post: 07-23-2010, 09:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •