/**
* @Description 容器简化版
**/
public class MyCollection implements ICollection {
private List list = new ArrayList();
@Override
public void add(Object obj) {
list.add(obj);
}
@Override
public void remove(Object obj) {
list.remove(obj);
}
@Override
public Iterator iterator() {
return new ConcreteIterator(list);
}
}
public class Main {
public static void main(String[] args) {
ICollection collection = new MyCollection();
collection.add("小滴课堂老王");
collection.add("小滴课堂Anna小姐姐");
collection.add("小滴课堂二当家小D");
collection.add("小滴课堂刘一手");
collection.add("小滴课堂老帆");
Iterator iterator = collection.iterator();
while (iterator.hasNext()){
Object obj = iterator.next();
System.out.println(obj);
}
}
}