Singelton pattern

Posted on October 15 2009 by Sachin Jain

Singelton pattern is required where we need single instance of class. Example in financial domain applications there is major requirement of security and class need to have single instance and no other can use same instance of the class.

We define singelton pattern as – Ensure a class has only one instance and provide a global point of access to it.

It is achieved by creating 1) Private constructor 2) Static methods.

Example

public class singelton

{

static singelton objSingle;

private singelton()

{

}

public static singelton print()

{

if(objSingle == null)

{

objSingle = new singelton();

}

return objSingle;

}

}

VN:F [1.9.0_1079]
Rating: 2.0/5 (1 vote cast)
VN:F [1.9.0_1079]
Rating: 0 (from 0 votes)
Singelton pattern, 2.0 out of 5 based on 1 rating

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Powered by Sachin Jain

Powered by Olark