How do we ensure that a class has only one instance and that the instance is easily
accessible? A global variable makes an object accessible, but it doesn't keep you from
instantiating multiple objects.

So what is the use of singleton pattern if we can create multiple instances?

I am sure there is something after that saying "That's why the constructor is private".
–
RigApr 11 '13 at 14:54

The "create no more than one instance" is usually a bogus requirement. You create only one instance if you need only one. But you won't die if more than one instance is created. Otherwise, you should rethink the design of the class.
–
donquixoteJul 9 '14 at 16:01

In the quote they don't talk about how to do it, but how not to do it.

Some approach for getting a singleton is to make the constructor private and write a own static method, that creates a new element on the first call, saves it in a static variable and always returns this object when called again.

There are very few languages that prevent you from shooting your foot if you really want to do it. The singleton pattern makes maintaining exactly one instance of the class quite trivial and creating multiple instances of it quite difficult; creating multiple instances unintentionally - impossible.

Most design patterns are to make programmer's life easier and remove their headaches. They can be circumvented and exceptions to them can be made. The singleton is to remove the headache of watching when and where you instantiate a class there should be only one instance of.

It's the kind of thinking "I'll catch cold on purpose, to spite my parents" if you try to create more than one instance of a class designated as singleton. Adult people don't do this.

Welcome to programmers.SE! I believe the OP had trouble understanding the concept of the singleton pattern, and not an issue with finding a way to create multiple instances. Try answering what the user specifically asked.
–
Rafael CichockiMay 29 '13 at 7:07