Reading other people\'s code, I\'ve seen a lot of:
List ints = new ArrayList();
Map map = new HashMap();
This (good) style of declaring the type as the Interface
the class implements is important because it forces us to use methods only defined in the Interface
.
As a result, when we need to change our class implementations (i.e. we find our ArraySet
is better than the standard HashSet
) we are guaranteed that if we change the class our code will work because both classes implement the strictly-enforced Interface
.