Skip to content

Instantly share code, notes, and snippets.

@mcsee

mcsee/decoupled.java

Last active Feb 4, 2021
Embed
What would you like to do?
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 protocol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment