就可扩展性而言,从具体类或接口创建对象会更明智?
例如,而不是:
LinkedStack<Integer> list = new LinkedStack<Integer>();
应该是这样的:
StackInterface<Integer> list = new LinkedStack<Integer>();
就可扩展性而言,从具体类或接口创建对象会更明智?
例如,而不是:
LinkedStack<Integer> list = new LinkedStack<Integer>();
应该是这样的:
StackInterface<Integer> list = new LinkedStack<Integer>();
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).