Please help me to understand the Factory pattern and the Singleton pattern, when we need to use the Factory pattern and when to use the Singleton pattern.
What is the main advantage/disadvantage of one over the other?
Any suggestion (explanation) will help me lot.
They do two very different things.
A Factory exists to create one or more copies of a class. It, or a method it exposes, can be provided to another class that needs the dependency, and the dependent class can call the factory method to get an instance.
A singleton exists to create one and ONLY one copy of a class. A reference to the class is obtained statically, but that reference can then be passed around as an instance, unlike a purely static class.