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