6

I am just looking for a reasonable answear how implementation of

java.util.Iterator 

is coming under State Design Pattern

EDIT

Please Refer the below Link

Examples of GoF Design Patterns in Java's core libraries

jaco0646
  • 15,303
  • 7
  • 59
  • 83
BOSS
  • 2,931
  • 8
  • 28
  • 53
  • 1
    I think, that you should take a look on [this answer](http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns/2707195#2707195). – Oleg Kuznetsov Jul 21 '11 at 10:02

2 Answers2

3

That, I am not sure. As far as I know, its an implementation of Iterator Design Pattern.

However, it can, wrongly, be said that it uses State Pattern, as calling next() affects the state of the Iterator object. But, IMO, its not really a State Pattern implementation, as it doesn't change the base object on which operation has to be executed. Wikipedia is having a fine Java example of State Pattern.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
2

To quote from the GoF book:

State: Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class.

This definitely does not sound like an Iterator. Neither are these two patterns mentioned as related in the book, btw.

Péter Török
  • 114,404
  • 31
  • 268
  • 329