Lecture overview -- Keyboard shortcut: 'u'  Previous page: Time complexity overview: Collection classes  -- Keyboard shortcut: 'p'  Next page: Generic Dictionaries in C# [Section] -- 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 21 : 36
Object-oriented Programming in C#
Collection Classes
Using Collections through Interfaces

It is an advantage to use collections via interfaces instead of classes

If possible, only use collection classes in instantiations, just after new

This leads to programs with fewer bindings to concrete implementations of collections

With this approach, it is easy to replace a collection class with another

/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/2/prog-class.csAn animal program - firmly bound to Collections - a problematic choice.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/2/prog-interfaces-1.csA program based on ICollection<Animal> - with a Collection<Animal>.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/2/prog-interfaces-2.csA program based on ICollection<Animal> - with a List<Animal>.


/user/normark/oop-csharp-1/sources/c-sharp/collections/collection/2/outputOutput from animal collection programs.