Answer the question
In order to leave comments, you need to log in
Is it correct to create a collection of interface type?
If I have a Car interface, and Mazda and Audi implement it (hidden advertising). Is the expression correct List<Car> list = new LinkedList<>();
or should I use an abstract/ordinary class to implement polymorphism?
Answer the question
In order to leave comments, you need to log in
Everything depends on the task. If you need a local array, then you can at least implement it. If this is a container where polymorphism is really needed, then it is better to increase the abstraction as much as possible. Those. if the interface is enough for you, then you should use it. If not, an abstract class. If not, the parent implementation. If it is not enough - a concrete class.
This is how it is done in Java. But you pay for a polymorphic call with runtime brakes. Therefore, without much sense, this should be avoided.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question