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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Question regarding Static Variables

  • 08-04-2009 11:45pm
    #1
    Registered Users, Registered Users 2 Posts: 3,804 ✭✭✭


    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, Registered Users 2 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, Registered Users 2 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