How can we prevent users from creating more than one instance of singleton object by using clone() method?

First we should not implement the Cloneable interface by the object that is a Singleton.

Second, if we have to implement Cloneable interface then we can throw exception in clone() method.

This will ensure that no one can use clone() method or Cloneable interface to create more than one instance of Singleton object.

Read the full book at www.amazon.com
Posted in Design Pattern, Design Pattern Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*