Custom Collections

Like Java, .NET makes it difficult to subclass concrete collection classes to provide specialized behavior without implementing large amounts of functionality. There always seems to be some vital method or inner class that is not accessible. Both languages provide abstract classes as the mechanism for custom designs, but we think that the .NET classes are better thought out.

The abstract classes in .NET are listed in Table 9-7.

Table 9-7. Abstract .NET Collection Classes

Class

Description

CollectionBase

Provides a basis for strongly typed collections.

ReadOnlyCollectionBase

Provides a basis for strongly typed collections that don’t permit elements to be modified.

DictionaryBase

Provides a basis for strongly typed collections of key/value pairs.

The most interesting aspect of these classes is that none of the collections detailed in this chapter are derived from them. There is no specific reason why custom collections have to be subclassed from one of these bases, but it is generally good practice to do so.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset