Professional Documents
Culture Documents
The programmer would access the single instance of this class by writing somethi
ng similar to
Singleton.getInstance().someMethod()
or similar to
Singleton s = Singleton.getInstance();
s.method1();
...
s.method2();
...
For a more complete discussion of the Singleton pattern, see the chapter Singleto
n in the book Design Patterns: Elements of Reusable Object-Oriented Software by t
he Gang of Four (Addison-Wesley, 1995), or the chapter Singleton in the book Pattern
s in Java, Volume 1 by Mark Grand (John Wiley & Sons, 1998). For information abo
ut variations on the Singleton Pattern, see the chapter entitled To Kill a Single
ton in the book Pattern Hatching: Design Patterns Applied by John Vlissides or th
e article Implementing the Singleton Pattern in Java by Rod Waldhoff.
6) Calendar is an abstract class. The getInstance() method tries to instantiate
GregorianCalendar() i.e., parent instantiating a derived class. This looks Non-O
O? Ex: Calendar a=Calendar.getInstance(); Can somebody explain why is it so?
The Calender class is an abstact class, true, however,the point you missed is th
at the getInstance() returns the " Calendar using the default timezone and local
e. " , in your case, the GregorianCalender a class that IS a Calender (a Suzuki
IS a car, a 747 IS a plane..the standard OO terminology. So what you get is a cl
ass that does some specialized work based on the default locale. Other methods