[模式之集思廣義] Prototype pattern

1.Concept

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. - Gof

2.QA

Clone    淺拷貝,複製值類型,不復制引用類型;引用indicate the same object.==
Copy    深拷貝,值類型與引用類型都做複製; Use the Serialization to deep copy the Object.

 

原型模式創造出的對象拷貝與原有對象存在以下關係。

1、原對象 != 新對象拷貝

2、原對象.equals(新對象拷貝) = true(前提是添加了適當的equals方法)

3、原對象.getClass().equals(新對象拷貝.getClass())

 

 

3.Good example.

DOTA, 劍聖,孫悟空。

發佈了78 篇原創文章 · 獲贊 18 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章