Lecture overview -- Keyboard shortcut: 'u'  Previous page: Sample use of class <b><kbd>Collection<T></kbd></b> -- Keyboard shortcut: 'p'  Next page: Specialization of Collections - a realistic example -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 10 : 36
Object-oriented Programming in C#
Collection Classes
Specialization of Collections

I want to make my own specialized/extended collection.
Which class should be selected as superclass of my collection class?

The class constructed from Collection<T> is a useful starting point

/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/try/animal.csA class Animal.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/try/farm.csA class AnimalFarm - a subclass of Collection<Animal> - testing protected members.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/try/prog.csA sample client of AnimalFarm - revealing use of protected Collection<Animal> methods.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/try/outputOutput from sample client of AnimalFarm.


  • The protected, virtual methods InsertItem, RemoveItem, SetItem, and ClearItems are called from all relevant methods in Collection<T>

  • Overridden members in AnimalFarm control the actual insertions and removals in the collection