Does the java.util.Iterator implementation use the State pattern?

I'm just looking for a reasonable answer, like implementation

java.util.Iterator 

is under the state design pattern

EDIT

See link below

Examples of GoF design patterns in Java core libraries

+6
source share
2 answers

This, I'm not sure. As far as I know, this is an implementation of an iterator design pattern .

However, we can say that it uses the State Pattern , since the next() call affects the state of the Iterator . But IMO, this is not an implementation of the State Pattern , since it does not change the underlying object on which the operation should be performed. Wikipedia has a great example of a Java State Template .

+3
source

To quote the GoF book :

State: allow the object to change its behavior when its internal state changes. It seems that the object will change its class.

It definitely doesn't look like an Iterator. These two patterns are not mentioned as related in the book, by the way.

+2
source

Source: https://habr.com/ru/post/893248/


All Articles