Skip navigation
YeahjustgimmeAscreenName
Currently Being Moderated

OOP using global vars, best way to do it?

May 4, 2012 6:19 AM

Tags: #global #oop #classes #global-vars

Ls,

 

Im a beginner when it comes to OOP.

Not wanting to pass everything thru the class calls, i want to be able to have  some  application globals.

 

Can  define them package level?

Should I create a class globals.as with static vars?

Whats the proper way of doing this?

 

Any help is greatly appreaciated.

 

Mac

 
Replies
  • Currently Being Moderated
    May 4, 2012 6:48 AM   in reply to YeahjustgimmeAscreenName

    firstly I would say that there are few instances where you would need global variables, I haven't used any in a long time and at the moment I can't think of any situation where i would. Although saying that it may be the easier solution if you are new to OOP.

     

    if I were to do this I would use a class with statics vars as you said

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2012 6:50 AM   in reply to YeahjustgimmeAscreenName

    yes, you can use a class that has static variables.  if you want your class to validate the variables, you can use private static variables and public getters and settings.  otherwise, you can use public static variables.

     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2012 4:23 PM   in reply to YeahjustgimmeAscreenName

    I dont use glabal vars anymore, more like a global class in the form of a Model that I inject into views (via presenters) using Swiz

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points