[Newbies] How to empty a collection?

Reinout Heeck reinz at desk.org
Tue Feb 19 13:46:10 UTC 2008


goran at krampe.se wrote:
> The *normal* way people usually do it thoiugh is to *not depend on the
> identity* of the Collection - different objects should typically not
> share the same Collection. And if you don't share - then the easy way
> out is to just do:
> 
> 	myCollection := OrderedCollection new "or whatever class you use"
> 
> ...in order to empty it.


A word of caution: identity should be preserved in the 'normal' case, 
replacing with another collection should be regarded as the exceptional 
case. Your assertion that "different objects should typically not share 
the same Collection." is only valid in limited cases.

I'm talking from my experience with building mvc-based apps on 
VisualWorks. Code needs to be decoupled, ie 'model' objects and 
collections should not know about the UI's that are coupled to them, 
this is achieved with the various dependency mechanisms available in VW.

Changing identity of the collections will break this paradigm big time 
(regardless of whether the dependents are managed in a global dictionary 
or by the collection itself).





As to the implementation of #removeAll on non-growable collections: 
follow whatever pattern the squeak library uses for other messages that 
alter the size (#add:, #remove:,...). In VW the idiom is to call 
#shouldNotImplement.



Cheers,

R
-


More information about the Beginners mailing list