1类图
2python示例
''' Created on 2017-2-10 @author: admin ''' from _overlapped import NULL from abc import abstractmethod class AbstractList: @abstractmethod def add(self,item):pass @abstractmethod def len(self):pass @abstractmethod def item(self,index):pass @abstractmethod def iterator(self):pass class MyList(AbstractList): def __init__(self,data=NULL): if(data==NULL): self.data=[]; else: self.data=data; def add(self,item): self.data.append(item) def len(self): return len(self.data) def item(self,index): return self.data[index] def iterator(self): return Iterator(self); class AbstractIterator: @abstractmethod def hasNext(self):pass @abstractmethod def next(self):pass class Iterator(AbstractIterator): def __init__(self,mylist): self.list=mylist; self.index=0; def hasNext(self): if self.index>=self.list.len(): return False else: return True def next(self): if self.hasNext(): data=self.list.item(self.index); self.index+=1; return data; else: raise Exception("index out of bound") if __name__ == '__main__': mylist=MyList([1,2,3,4,5,6,7,8,9]); it=mylist.iterator(); while it.hasNext(): print(it.next(),end=",");