mercredi 9 juin 2021

which is better to use function with singleton object or static function with class

If both don't have any difference then why singleton pattern comes into existence. If someone knows about good article or blog please share with me.

Singleton Object:

class Singleton{
   private static Singleton singleton = null;
   public static getInstance(){
      if(singleton == null) 
      singleton = new Singleton();
      return singleton;
   }

   public String getData() return "";

}

Static Function:

class Static{
    public static String getData() return "";
}

Aucun commentaire:

Enregistrer un commentaire