4

In WPF and Silverlight, we have seen the following classes:

  • UIElementCollection
  • ItemCollection
  • RowDefinitionCollection
  • ColumnDefinitionCollection
  • PointCollection
  • and a lot more....

Why do they have these classes, one class for each type? Why did they not use generic classes such as Collection<T>?

Also, I've seen in Silverlight, all of these classes have been derived from PresentationFrameworkCollection<T> , as

public sealed class ItemCollection : PresentationFrameworkCollection<Object> 
public sealed class PointCollection : PresentationFrameworkCollection<Object> 
public sealed class IconCollection : PresentationFrameworkCollection<Object> 
//and so on...

If all of these derive from a common class, and I don't see anything public in the derived classes (all of them are empty!), then why did they define them in the first place? I feel that there are some differences which are either declared private or internal in the derived classes. But I don't exactly know.

Please help me understanding the design of these classes. In particular, why did they use them instead of generic classes which come with the framework? What are the benefits?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • That's like saying what's the difference between a car manufacturing plant and a junkyard - they both manage a collection car parts. – Alain Aug 08 '11 at 12:22
  • 1
    What's the difference between a swiss-army knife and a toolbox? – Alain Aug 08 '11 at 12:24
  • 1
    @Alain: Your comments didn't help me in any way. I'm still ignorant. – Nawaz Aug 08 '11 at 12:28
  • I'm alluding to the fact that having a generic collection of things is not always useful, it takes an enhanced class to perform special operations on those things and organize them in a way that makes sense only for those things - features which a generic collection class can't provide. – Alain Aug 08 '11 at 12:33
  • @Alain: I can guess that. But I'm still ignorant. What "special operations" are you talking about? I'm looking for some concrete knowledge. :-) – Nawaz Aug 08 '11 at 12:38
  • As an example, collections that deal with Interface elements handle UI-specific needs such as setting up event handlers, determining when the child elements need to be refreshed, performing clones without crossing event-handler wires, etc. Best way to see it just to look at the msdn class description for each and see how much they differ, eg: http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcollection.aspx – Alain Aug 08 '11 at 15:57

1 Answers1

6

They internally work different, based on the use case they were designed for. For example, UIElementCollection doesn't just hold the elements, but also makes sure they are added and removed from the corresponding visual tree...

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443