C ++ Static Methods Singleton Vs

Possible duplicate:
C ++ singleton vs fully static object

Hi,

why should I use a singleton over static class methods.

    MoneyPrinter::addJob(PrinterJob &job);
or
    MoneyPrinter::getInstance().addJob(PrinterJob &job);

Is this just a matter of style? What are you using? Why?

ps. I know that sigletones are not thread safe by default (first initialization).

+5
source share
4 answers

The syntax gives you control over when the class is instantiated, and how DeadMG tells you if which one you want to create. A static class is less manageable and is created when main is called.

, , , - , main.

, singleton , , . ( Effective ++), , .

+2

( - ), .

? ?

, , .

, ( " " " " ).

+5

The general rule of singles, if you must ask, do not use it. This is true for any changeable state in the world.

+3
source

It would be harder to reorganize Singleton-ness simply because of the syntax used if you are using static member functions. There is one reason.

+2
source

All Articles