需求

设计模式(23) -- 迭代器模式

传统模式

设计模式(23) -- 迭代器模式
设计模式(23) -- 迭代器模式

迭代器

基本介绍

设计模式(23) -- 迭代器模式

类图

设计模式(23) -- 迭代器模式
对原理
类 图的说明 即 迭代器模 式的角色及职 责
1)Iterator 迭代器接口,是系统提供,含义 hasNext, next, remove
2)ConcreteIterator : 具体的迭代器类,管理迭代
3)Aggregate : 一个统一的聚合接口, 将客户端和具体聚合解耦

迭代器模式应用实例

类图

设计模式(23) -- 迭代器模式

代码:

Department
设计模式(23) -- 迭代器模式
College
设计模式(23) -- 迭代器模式
ComputerCollege
设计模式(23) -- 迭代器模式
ComputerCollegeIterator
设计模式(23) -- 迭代器模式
InfoCollege
设计模式(23) -- 迭代器模式
InfoColleageIterator
设计模式(23) -- 迭代器模式
OutPutImpl
设计模式(23) -- 迭代器模式
Client
设计模式(23) -- 迭代器模式
运行结果:
设计模式(23) -- 迭代器模式

迭代器模式在 JDK ArrayList 集合应用的源码分析

设计模式(23) -- 迭代器模式
设计模式(23) -- 迭代器模式

迭代器模式的注意事项和细节

设计模式(23) -- 迭代器模式


相关文章: