I am doing the B&S SCJD and I hoped to make my Data.java into a singleton. Before I jump into my real question I would like to ask if this is even a viable design pattern.
I read much about about singletons on internet and it doesnt look like this is a pattern that goed sown well with other developers and possibly the exam asessor too. However should I go ahead I want to know the following...
To use an enum of not to hold the instance? I read up on this and many see it as the best way to ensure that your singleton is in fact a "singleton".
another question...
In all the examples of singletons I have only seen once that a programmer included an Exception that ensured that his singleton can not be cloned. If one creates a singleton, is cloning the only possible way that an extra instance can be created of your singleton or are there other ways? If cloning is all I have o consider then I may as well go ahead an include such an exception in my code.
Regards.
I read much about about singletons on internet and it doesnt look like this is a pattern that goed sown well with other developers and possibly the exam asessor too. However should I go ahead I want to know the following...
To use an enum of not to hold the instance? I read up on this and many see it as the best way to ensure that your singleton is in fact a "singleton".
another question...
In all the examples of singletons I have only seen once that a programmer included an Exception that ensured that his singleton can not be cloned. If one creates a singleton, is cloning the only possible way that an extra instance can be created of your singleton or are there other ways? If cloning is all I have o consider then I may as well go ahead an include such an exception in my code.
Regards.