Composite Iterator has different code when I did it in C#
Can you please explain me, What am I missing here?
In the code file CompositeIterator.java @ https://github.com/bethrobson/Head-First-Design-Patterns/blob/master/src/headfirst/designpatterns/composite/menuiterator/CompositeIterator.java
Line number 13 has a if condition
if (hasNext()) {
It also returns null in case it doesn't have hasNext()
In order to traverse through the Menu and MenuItems I had to remove that If condition. You can see the code @ https://github.com/VikramShetty/Fundamentals/blob/master/IteratorAndComposite/CompositeEnumerator.cs
You will find the commented code from line 19th in the above file.
So my question is why is the code not recursively walking the object hierarchy when I have that If condition in my code.
Thanks in Advance. Waiting for your reply. Vikram