Praison Selvaraj wrote:The Singleton Pattern can be used here to control the number of instances that are created.
As indicated by the name 'Singleton', it does not necessarily mean that a Single instance is for maintaining a single instance. It just means that this pattern can be used to control the number of instances.
You can't just decide that a pattern means what you want it to mean. The singleton pattern is exactly what it says it is. It means you can only have one instance of a given class at any time. Not 2, not 3, but 1.
Bear is right, Factory pattern would be the way to go here, and then look at object pooling techniques.