Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Question regarding Static Variables

Options
  • 09-04-2009 12:45am
    #1
    Registered Users Posts: 3,803 ✭✭✭


    I make alot of my commonly accessed variables static. For example, in XNA I would make my GraphicsDevice, InputHandler and Camera objects static as these would be accessed frequently by a variety of different classes. I would do the same for other objects that are used frequently by different classes.

    But is this considered bad practice?


Comments

  • Registered Users Posts: 885 ✭✭✭clearz


    I personally wouldn't make my classes static just because I am too lazy to pass objects around if thats what you are talking about but everybody to themselves Don't know much about XNA (Have only used the DirectX SDK with C++) but if I where to guess I'd say that your GraphicsDevice class and InputHandler should be fine. Not to sure about the Camera one but (maybe in the future you may need multiple camera classes to do things like add CCTV to your games. Have you looked at Singletons might be better again. You've provided very little info to go on.


  • Registered Users Posts: 981 ✭✭✭fasty


    Having a few static objects isn't necessarily a bad thing, in particular when they represent a resource loader or a graphics device. It's common enough in game development but even more common is using the singleton pattern as suggested above (ugh, I hate "pattern" talk) to get a reference to a single object that's only created once.


Advertisement