天天看點

設計模式-原型模式

設計模式-原型模式

設計模式-原型模式

效果:

設計模式-原型模式

原型模式,其實就是完整的複制一個對象,以一個對象為樣本,進行複制作業,然後再來使用.

以下以複制一個uiview的操作來講解原型模式的實作

注:uiview對象是不能夠複制的,我們需要完整的把uiview對象的參數都複制了後,就行了.

<a href="http://stackoverflow.com/questions/4425939/can-uiview-be-copied" target="_blank">http://stackoverflow.com/questions/4425939/can-uiview-be-copied</a>

your app probably crashes with something like:

the reason is that uiview does not implement the copying protocol, and therefore there is no <code>copywithzone</code> selector in uiview.

因為uiview沒有實作複制的協定,是以也就不能複制uiview了.

uiview+prototype.h 與 uiview+prototype.m

使用:

需要注意的地方:

設計模式-原型模式

繼續閱讀