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 together  Annotated slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Alphabetic index  Help page about these notes  Course home    Collection Classes - slide 21 : 36

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

prog-class.cs
An animal program - firmly bound to Collections - a problematic choice.
prog-interfaces-1.cs
A program based on ICollection<Animal> - with a Collection<Animal>.
prog-interfaces-2.cs
A program based on ICollection<Animal> - with a List<Animal>.
output
Output from animal collection programs.