Martin Fowler on Typed Collections

From Martin Fowler:

When people are starting to work with objects, particularly in a strongly typed language, a common question is whether they should have specific collection classes for different domain types. So if you have a company class which stores a collection of employees, should you use a regular collection class from your libraries, or should you create a specific EmployeeList class - a typed collection?
Via Sam Gentile's Blog

3 Comments

  • He's wrong. Typed lists are great, because you can use typed indexers which make the usage of those typed lists a breeze. Also, typed lists can contain extra code per type, if you require it, f.e. extra constructors.





    Why are so many people so happy with this guy? Most of the time he says things, it's OR common knowledge we know for decades (knowledge based on yourdon cs.) OR painfully wrong material that can better be ignored (this bliki f.e. or his craparticle about evolutional database design *shiver*).

  • I was not agreeing nor disagreeing with his opinion -- merely posting it as one view. Personally, I prefer typed lists because of the safety and some of the "extra" things that you posted.





    It's one of those "it depends" situations. Some solutions may not need (or have the time) for a strongly-typed collection.

  • Strongly typed collections have their purpose, but only when you decide to add your own logic. I for instance do when:





    myPersonCl.Contains("Paul Gielens");





    Contains(string name);

Comments have been disabled for this content.