Sollicitatievraag bij Netflix

What is Singleton Design pattern?

Antwoord op sollicitatievraag

Anoniem

12 apr 2012

Singleton design patterns deals with where you need a single instance of the class which has to be shared among multiple resources. Singleton design pattern is used in Logger class,Shared Resource environment. Example of singleton: public class singleton{ private static singleton instance=new singleton(); private singleton(){ } public ststic getinstance() { return instance; } } another synchrinized way : public class singleton{ private static singleton instance; private singleton(){ } public static getinstance(){ if (instance==null) { synchronized(singleton.class) { if(instance==null) { instance=new singleton(); } } } return instance; } }