Last active
February 20, 2025 19:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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