I'd like to implement Null Object design pattern for Iterable class. For example if my internal array isn't initialized, wrapper class anyway returns empty Iterator that doesn't break main logic:
public function iterator():Iterator<T> {
// ...of cause it doesn't work, because Iterator is typedef not class
return mList != null ? mList.iterator() : new Iterator<T>();
}
var mList:Array<T>;
Should I instantiate static empty dummy array with desired type of items or something else that implements Iterator interface but contains nothing? Or may be there is more straight solution?
Aucun commentaire:
Enregistrer un commentaire