[Newbies] How to deep copy elements when using collectons?

Xinyu Liu liuxinyu95 at gmail.com
Tue Jan 1 13:31:02 UTC 2008


Hi,

I have a junior question when using collection to store/get my own defined
element.
My elements is defined as below:

Object subclass: #MyItem
    instanceVariableNames: 'subItems'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'MyTest'


Where the subItems instance var is also a collection.

But I don't know how to store/get such kind of MyItem by using collection, I
think I need deep copy an element when add it to the collection.

I don't think the following code works.

|temp coll|
temp := MyItem new.
temp addSubItem: 'hello'; addSubItem 'world'; yourself.
coll := OrderedCollection new.
coll add: temp

How can I add the deep copied element to my collection and retrieve it
later? shall I overload the #copy method?

Best regards and thanks
-Xinyu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080101/b7c642ea/attachment.htm


More information about the Beginners mailing list