RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Sunday, December 4, 2011

Classic Singleton example

A classic and fool-proof example of Singleton sample is as follows,

Considering that we need to create a singleton for an Employee object(some POJO, for easier understanding), a Singleton can be expressed as,

class SampleSingleton{
private static Employee empObject= new Employee();
public static Employee getEmployee(){
return empObject;

On start up, I create a singleton object and assign it to the empObject, and each time I only send that single object to the caller.

No comments: