The first form is recommended for the public interface of a class (for example, declaring attributes in a class). This is a well-known tip that you should program for the interface, and not for a specific implementation (as indicated in Design Patterns ) - the number of classes that you need to import have little to do with the quality of the code and good design.
The advantage of the first form is that it will allow you to easily replace implementations later if the need arises, while the second implementation inherits the implementation class, making your code more difficult to develop and less flexible.
There are times when you can declare and use specific classes, though (for example, for low performance in performance). But the public interface of the class should use interfaces if possible, this will facilitate the implementation of future changes.
source share