Skip to main content
2 of 2
deleted 2 characters in body
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Mostly this is due to the Interface Segregation Principle. You want your client code to depend on as small an interface as necessary, and that means the most abstract class. This isolates your code here from changes in the derived classes that you don't care about.

Another benefit is if you make a mistake and instantiate a class that doesn't actually implement the interface, or perhaps that code is changed later so that it no longer implements the interface, the compiler error will point you to the line where it is declared, rather than later down where it makes less sense.

It's all about adopting style choices that minimize the possibility of introducing errors, and make it easy to find those errors when you do make them.

Karl Bielefeldt
  • 148.9k
  • 38
  • 285
  • 485