Custom Collections and whether to use inheritance or not

I will talk about Windows Communication Foundation collections in the next post and wanted to get this out of the way ; I'm always lost when creating a simple collection whether to contain a collection as a member or whether to extens a base one via in extion

eg

public  class Customers<Customer> or  Customers Collection < Customer> { ..}

vs

public  class Customers  ; ICollection<Customer>

{  private List<Customer>  customers ; //Add etc  }

While the second is  obviously better as you can hide elements i dont think its good use of time to implement each such collection unless the collection requires significant extentions anyaway.  A good example is a collection with indexes

public  class Customers  ; ICollection<Customer>

{

Dictionary<Customer,int> customers;

Dictionary<Customer,string> customerByNameIndex;

Dictionary<Customer,string> customerByCityIndex;

}

 

 

 

 

Print | posted on Tuesday, January 13, 2009 7:47 PM

Feedback

No comments posted yet.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 6 and 6 and type the answer here: