Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active February 20, 2025 19:10
Show Gist options
  • Select an option

  • Save mcsee/0358951abbf771f2b63a3ae6833ea210 to your computer and use it in GitHub Desktop.

Select an option

Save mcsee/0358951abbf771f2b63a3ae6833ea210 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public interface Iterator {
public bool HasNext { get; set;}
public object Next();
}
public Iterator Reverse(Iterator iterator) {
var list = new List<int>();
while (iterator.HasNext) {
list.Insert(0, iterator.Next());
}
return new ListIterator(list);
}
public class MyCollection implements Iterator {
public bool HasNext { get; set;} // Implementation details
public object Next(); // Implementation details
}
public class myDomainObject sum(Iterator anObjectThatCanBeIterated) {
// Loose coupling
}
// Can use any Iterator
// (even a mocked one as long as it adheres to the protocol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment