design patterns - What are singletons?? how to use them?? and why to use them? -


possible duplicate:
singleton: how should used

hello. want know singleton is? how use it? , why have use it. thank much. if can give examples explanation appreciate it.

if need single instance of object, use singleton. 1 of many standard design patterns.

let me clarify piece of code -

public class singleinstance {     private static final singleinstance onlyinstance = new singleinstance();   // or other value      // private constructor, instance cannot created outside class     private singleinstance(){};      public static getsingleinstance()     {         return onlyinstance;     } } 

since class's constructor private, cannot instantiated in application, ensuring have 1 instance of class singleinstance.

use pattern when need ensure 1 instance of particular class created within entire application.

to learn more, go here.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -