別的不說,singleton 沒答好,有點兒說不過去。

來源: mdq100 2009-03-04 20:39:56 [] [博客] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (434 bytes)
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.

所有跟帖: 

謝師祖教誨。 -吳用先生- 給 吳用先生 發送悄悄話 (0 bytes) () 03/04/2009 postreply 22:09:19

回複:別的不說,singleton 沒答好,有點兒說不過去。 -ncpga- 給 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- 給 mdq100 發送悄悄話 mdq100 的博客首頁 (170 bytes) () 03/05/2009 postreply 20:21:33

噢,謝謝。我還真沒用過serialization /deserialization -戲雨飛鷹- 給 戲雨飛鷹 發送悄悄話 戲雨飛鷹 的博客首頁 (762 bytes) () 03/05/2009 postreply 20:43:54

basiaclly yes. -mdq100- 給 mdq100 發送悄悄話 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- 給 bluemont 發送悄悄話 (0 bytes) () 03/05/2009 postreply 19:28:02

這麽複雜?那COPY$PASTE是8是很難?哈哈。。 -戲雨飛鷹- 給 戲雨飛鷹 發送悄悄話 戲雨飛鷹 的博客首頁 (69 bytes) () 03/05/2009 postreply 20:00:33

隻要不謾罵,歡迎交流。換馬甲也沒關係。 -mdq100- 給 mdq100 發送悄悄話 mdq100 的博客首頁 (0 bytes) () 03/05/2009 postreply 20:17:12

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”