What is the difference following statement between?
List myList = new ArrayList(); and ArrayList myList = new ArrayList();
Above declarations look exactly the same in a short program, but if you go on to use
myList 100 times in your program you can start to see a difference. The first
declaration ensures that you only call methods on myList that are defined by the
List interface (so no ArrayList specific methods).
If you've programmed to the interface this way,
later on you can decide that you really needList myList = new TreeList(); and you only have to change your code in that one spot.
You already know that the rest of your code doesn't do anything
that will be broken by changing the implementation because
you programmed to the interface.