• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encapsulating collection membership  RSS feed

 
Malcolm Storey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my multi-windows app, am going to need various collections of my own objects. Am wondering whether it is better to:
A. encapsulate membership in member object creation (via factory method - don't want premature exposure!)
B. let the creator handle membership

Encapsulation makes managing membership over new/dispose cycles much less error prone and also facilitates a Dispose() method to unhook the object from all Collections of which it is a member. (This would be through my own Collectable interface.)

This naturally leads to a hierarchy of collections (app<-windows<-page-<my_primitives) which would be recursively iterated on Dispose(). [Yes, this is over-kill - some of those collections would also be being Disposed, but it would make life easier for GC and not worth trying to programmatically avoid. Dispose() will do other things too.]

Is this good design or am I getting carried away by the fun of it all?
[ November 18, 2008: Message edited by: Malcolm Storey ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!