Re: static props and methods = global variables??
From: Stu Smith (stuarts_at_nospam-digita.com)
Date: 07/19/04
- Next message: Joel Wilson: "Re: Performance cost of casting"
- Previous message: ansna: "FileIOPermission Error on Client-Server"
- In reply to: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Next in thread: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Reply: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 19 Jul 2004 16:03:53 +0100
"Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@comcast.netNoSpamM> wrote
in message news:%23Z428X0aEHA.3352@TK2MSFTNGP12.phx.gbl...
> The only question to ask is how often the items are going to be used. If
I think it's also worth considering lifetime as well. A global variable can
have an unclear or badly defined lifetime, and that can cause you problems.
> regularly, then keeping variables in memory is not a bad thing. I
routinely
> use a singleton for application settings. The singleton stores all sorts
of
As an example, do these app settings ever get written as well as read? If
not then fine, but if so you have a lifetime issue -- when do they get
written? As another example, what if the application settings need to change
midway through execution?
Many types of static/global data could really be considered a cache of some
sort (as in the app config example), and the golden rule there is "caching
implies policy" -- if you can't tell me the policy, you're likely to have
problems.
(And to anticipate Mr. Beamer's reply, the policy there is probably
'read-only; lifetime must extend at least until last access; small data vs.
relatively slow access to original data makes it worth it').
> vars, which makes a convenient object that can be used again and again. As
a
> singleton, it gets created the first time it is requested, so I do not
have
> an app ramp up time, per se.
>
> Static variables/properties are a good means of holding config type
> information, if that is what you are asking. Static methods are great for
> helper methods that do not require individual state.
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> ************************************************
> Think Outside the Box!
> ************************************************
> "Daniel Billingsley" <dbillingsley@NO_durcon_SPAAMM.com> wrote in message
> news:OCkv3U0aEHA.3988@tk2msftngp13.phx.gbl...
> > I'd like to set (on launch) and then keep some AppDomain-wide variables.
> >
> > Is there anything "bad" with doing something like this (dumb example),
or
> is
> > there another more "standard" way of accomplishing it?
> >
> > public class SomeInfo
> > {
> > private static _someText;
> >
> > public static string Text
> > {
> > get { return _someText; }
> > }
> >
> > public static void SelectText(int option)
> > {
> > if (int==1)
> > _someText = "one";
> > else
> > _someText = "something else";
> > }
> >
> > }
> >
> >
>
>
- Next message: Joel Wilson: "Re: Performance cost of casting"
- Previous message: ansna: "FileIOPermission Error on Client-Server"
- In reply to: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Next in thread: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Reply: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: static props and methods = global variables??"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|