View RSS Feed

Design Patterns


Rate this Entry
by , 03-09-2012 at 07:50 PM (660 Views)
If the interface is being implemented by the Singleton class ( when serialization and deserialization of singleton takes place more than one time) then number of Singleton instances will be created. For avoiding this, implement the readResolve method.
Java Code:
	public class Singleton implements Serializable {

		// This method is called immediately after an object of this class is deserialized.
		// This method returns the singleton instance.
		protected Object readResolve() {
			return getInstance();

Submit "Serialization" to Facebook Submit "Serialization" to Digg Submit "Serialization" to Submit "Serialization" to StumbleUpon Submit "Serialization" to Google

Singleton Pattern