Re: When is it appropriate to use static methods?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: AlexS (salexru2000NO_at_SPAMsympaticoPLEASE.ca)
Date: 05/10/04


Date: Mon, 10 May 2004 15:12:20 -0700

IMO, statics are simplified equivalents of singletons. They grow from
globals - functions or variables. There is not much more.
I would suggest statics
- when you need global method, property or function
- when you need global variable
- when you need singleton, which exists during whole application lifetime

I found it easier to code singletons using statics. Excellent examples -
such classes like SystemInformation or Environment.

HTH
Alex

"Tom" <nfr@nospam.com> wrote in message
news:%23vNmFSrNEHA.2976@TK2MSFTNGP10.phx.gbl...
> This is not intuitivelly clear.
>
>



Relevant Pages

  • Re: When is it appropriate to use static methods?
    ... Should I make all the methods in a singleton static? ... statics are simplified equivalents of singletons. ... > globals - functions or variables. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Developing/compiling software
    ... is when people get obsessive about globals and think that it is somehow ... on smaller PICs, doesn't use global statics. ... extern unsigned int GetCurrentPID(void); ... extern unsigned int currpid; ...
    (comp.arch.embedded)
  • Re: VC++2008: STL access violation depending on runtime library being used -- bug or undefin
    ... So declaring a global object containing references to other globals is ... The trick of defining static objects at function scope (and returning ... construct examples of this random behaviour with two "function statics", ...
    (microsoft.public.vc.language)
  • Re: static, global variable memory allocation
    ... Q. What are the memory allocation for static variable in a function, ... You would just have to keep your legs crossed if someone is running a program with logs of globals and statics filling up the head. ... Also the machines without a stack will obviously not allocate automatic variables on the stack, ...
    (comp.lang.c)
  • Re: Class Constants - pros and cons
    ... But Joshua was talking about using instances of Color, where those instances are singletons (well, flyweights is probably the right term when there are several of them), exposed in static final fields on Color, and the class is written in a certain way, which i take to mean having a private constructor, not creating any instances other than those in the statics, and implementing readResolve. ... I was focused on String constants and should not have used 'Color' instances as an example, ...
    (comp.lang.java.programmer)