'In terms of scalability would be wiser to make an object from the concrete class or the interface? [closed]

For example instead of:

LinkedStack<Integer> list = new LinkedStack<Integer>();

Should be this:

StackInterface<Integer> list = new LinkedStack<Integer>();


Solution 1:[1]

In my opinion:

LinkedStack<Integer> list = new LinkedStack<Integer>();

is better only if you need specific methods on LinkedStack that are not declared in StackInterface.

StackInterface<Integer> list = new LinkedStack<Integer>();

is better if you do not, because then you can 'plug in' any implementer of the interface for different reasons (efficiency reasons for example).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1