Skip to main content
Inspiring
January 5, 2009
Question

Where/how should I store static variables?

  • January 5, 2009
  • 1 reply
  • 1298 views
I have a Cairngorm project that reuses a specific value throughout the application (i.e. as an argument for several WebService calls). Where/how should I store/access this value? What is the best practice?

Right now, I am storing the value as a static public variable in the Model:

[Bindable]
public class ModelLocator
{
static public var __instance:ModelLocator = null;

static public var APP_CLASS_ID:int = 4;
}

And accessing it through the Class:

ClassIdNmb: ModelLocator.APP_CLASS_ID
This topic has been closed for replies.

1 reply

Participant
January 26, 2009
Hey Eric,

Since your stating that this variable is used with a web service it would make sense to store this variable in the ServiceLocator. You could look at storing it in the mx:Application if you used it as a variable passed in to the ServiceLocator as another option. I wouldn't store this variable in the model since it has nothing to do with model (from what your saying). My rule of thumb for storing things in the model is that they should be used in the view since your view is a visual representation of your model. So if it is not used in a view then it I would suggest it is in the wrong location.

Cheers,
Ross