Thursday, December 24, 2009

Singleton Pattern with Lazy Initialization On Demand Holder

This is one of the better ways to implementing a singleton class (class which lets user create one and only one instance).

It uses Initialization on demand holder pattern.



public class Singleton {
private static class LazyHolder {
private static final Singleton instance = new Singleton();
}

public static Singleton getInstance() {
return LazyHolder.instance;
}

private Singleton() {
//initialize singleton instance
}
}

No comments:

Using a Console Cable (USB TTL Serial Cable) with Raspberry Pi 3

A console cable provides terminal access to Raspberry Pi from say a laptop host without requiring to connect a monitor to Pi's HDMI port...