samedi 9 juillet 2016

Which is the appropriate design pattern(singleton/factory pattern) in the following scenario?

I have read/write actions in my project something similar in this link

The suggested pattern in the answer was Singleton Pattern which is implemented with enum. But I have come across my code where we are following

  1. Interface containing read/write methods says ClassA
  2. Implementation of the interface methods ClassAImpl
  3. Factory class contains the code as follows

      public class ClassAFactory { 
    
           public static ClassAFactory getInstance() throws Exception {
    
                 return new ClassAImpl();
             }
        }
    
    

    I have the following doubts

  1. Which is the apt design pattern to organize the code here in this scenario?
  2. What is the advantage of reusing the same instance again and again, rather than creating a new instance?

Someone please help me to know about this.

Aucun commentaire:

Enregistrer un commentaire