我想在
java中实现一个Stack(使用list interface:
Interface List).
我想以两种不同的方式实现它:使用组合和继承.
对于继承,到目前为止我有:
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class StackInheritance implements List {
//implement list methods
}
对于作文,我有:
import java.util.List;
public abstract class StackComposition implements List {
// implement some standard methods
}
public class StackViaList extends StackComposition {
// implement methods that have not been implemented in the abstract
// class
}
我很困惑从哪里开始.我之前从未使用过接口,所以我是否应该使用List方法来“模仿”堆栈,例如使用Array或ArrayList?
另外,对于合成,我不明白应该在StackComposition中使用哪些方法以及应该在StackViaList中使用什么方法.在不完全理解接口以及继承和组合之间,我有点迷失.我似乎还不能“得到它”……
任何帮助将不胜感激,谢谢!