开发者

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

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 libra开发者_如何学编程ries


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜