Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite Iterator has different code when I did it in C# #8

Open
VikramShetty opened this issue Apr 13, 2017 · 0 comments
Open

Composite Iterator has different code when I did it in C# #8

VikramShetty opened this issue Apr 13, 2017 · 0 comments

Comments

@VikramShetty
Copy link

VikramShetty commented Apr 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant