<分区>
Possible Duplicates:
What does it mean to program to a interface?
Interface List - java
你好。我被要求在几个类中使用接口(interface)列表。我的老师说,这是为了将来更容易交换实现。我被要求尽可能用 List 替换 ArrayList,但我仍然不完全确定这意味着什么。我想我了解什么是界面,但不确定如何继续进行更改。
例如,这是我应该用 List 修改所有 ArrayList 位的类之一的第一部分。感谢任何帮助
public class Simulator
{
// Constants representing configuration information for the simulation.
// The default width for the grid.
private static final int DEFAULT_WIDTH = 70;
// The default depth of the grid.
private static final int DEFAULT_DEPTH = 40;
// List of animals in the field.
private ArrayList<Animal> animals;