In Java, the latest Singleton pattern, use enum instead of a regular class. It's that simple.
The reasoning based on Joshua's is that serialization can cause issues. If a class implements Serializable, then after serialized and deserialized, a new instance can be created if the instance variables are not transient.
If you can answer the above, you will be guaranteed to pass the Singleton question.
Good luck.
別的不說,singleton 沒答好,有點兒說不過去。
所有跟帖:
•
謝師祖教誨。
-吳用先生-
♂
(0 bytes)
()
03/04/2009 postreply
22:09:19
•
回複:別的不說,singleton 沒答好,有點兒說不過去。
-ncpga-
♂
(158 bytes)
()
03/05/2009 postreply
09:26:00
•
It was a C++ interview,
-吳用先生-
♂
(467 bytes)
()
03/05/2009 postreply
10:44:10
•
why it needs a copy ctor? why make copy constructor "protected"
-戲雨飛鷹-
♀
(356 bytes)
()
03/05/2009 postreply
11:50:35
•
the interviewer said
-吳用先生-
♂
(186 bytes)
()
03/05/2009 postreply
12:31:48
•
ok.
-戲雨飛鷹-
♀
(0 bytes)
()
03/05/2009 postreply
12:40:14
•
師祖爺呀,你的singleton說得也忒深奧了。夠俺回味好幾年得了。。 ~~~
-戲雨飛鷹-
♀
(26 bytes)
()
03/05/2009 postreply
12:18:58
•
是啊是啊,也很高興飛鷹姐姐親臨指導,沒想到
-吳用先生-
♂
(48 bytes)
()
03/05/2009 postreply
12:34:56
•
看似容易,其實還是有點學問的。
-mdq100-
♂
(170 bytes)
()
03/05/2009 postreply
20:21:33
•
噢,謝謝。我還真沒用過serialization /deserialization
-戲雨飛鷹-
♀
(762 bytes)
()
03/05/2009 postreply
20:43:54
•
basiaclly yes.
-mdq100-
♂
(237 bytes)
()
03/05/2009 postreply
20:55:48
•
Thanks, 100...
-戲雨飛鷹-
♀
(0 bytes)
()
03/05/2009 postreply
20:58:13
•
nonsense, 又不用你發明singleton. 知道singleton是什麽意思,會COPY$PASTE 就行.
-bluemont-
♂
(0 bytes)
()
03/05/2009 postreply
19:28:02
•
這麽複雜?那COPY$PASTE是8是很難?哈哈。。
-戲雨飛鷹-
♀
(69 bytes)
()
03/05/2009 postreply
20:00:33
•
隻要不謾罵,歡迎交流。換馬甲也沒關係。
-mdq100-
♂
(0 bytes)
()
03/05/2009 postreply
20:17:12