-3

I am from JAVA so please please guide me if i am wrong.

In Java we mostly use a singleton class and create all the class objects thought the singleton class.

What about in c++?

I know we can use singleton but mostly while going through most of the stack overflow questions. Most of them says it's not good to use singleton in c++

Can you recommend some book or some project which will be easy to understand?

Kathick
  • 1,395
  • 5
  • 19
  • 30
  • Way too broad a topic to deal with on S.O. – DarenW Mar 11 '13 at 13:15
  • 1
    "....we mostly use a singleton class and create all the class objects thought the singleton class...." - are you referring to a bean factory for a dependency injection engine? – duffymo Mar 11 '13 at 13:15
  • 1
    The factory factory paradigm is not a plus for Java either. – Steve-o Mar 11 '13 at 13:16
  • Large Scale C++ Software Design by Lakos is a quite old, but fabulous. – Peter Wood Mar 11 '13 at 13:18
  • 1
    Just to note this isn't a good question for stack overflow. The [question asking for books](http://stackoverflow.com/q/388242/1084416) is still there but only because it's so useful, not because it fits SO format well. – Peter Wood Mar 11 '13 at 13:20

1 Answers1

2

Whether you're writing in C++ or Java singletons have many, bad implications.

They make it very difficult to test as their static nature preculdes late binding to, say, sway a real database with a stub that's quicker and has fewer depencies.

They also provide a fig leaf for global variables, trying to make them masquerade as a good design decision. Take a look at the alternatives, it'll pay off in a better design. You may want to look into dependency injection for ways to design a more testable system without singletons.

Paul Rubel
  • 26,632
  • 7
  • 60
  • 80