当前位置: 首页 > news >正文 网站建设维护培训会上的讲话wordpress编辑文章图片文字对齐 news 2025/10/28 2:57:47 网站建设维护培训会上的讲话,wordpress编辑文章图片文字对齐,菜单设计制作网站,福建做网站经典的设计模式有23种#xff0c;但是常用的设计模式一般情况下不会到一半#xff0c;我们就针对一些常用的设计模式进行一些详细的讲解和分析#xff0c;方便大家更加容易理解和使用设计模式。 1-原理和实现 迭代器模式#xff08;Iterator Design Pattern#xff09;但是常用的设计模式一般情况下不会到一半我们就针对一些常用的设计模式进行一些详细的讲解和分析方便大家更加容易理解和使用设计模式。 1-原理和实现 迭代器模式Iterator Design Pattern也叫作游标模式Cursor Design Pattern。它用来遍历集合对象。这里说的“集合对象”也可以叫“容器”“聚合对象”实际上就是包含一组对象的对象比如数组、链表、树、图、跳表。迭代器模式将集合对象的遍历操作从集合类中拆分出来放到迭代器类中让两者的职责更加单一。 迭代器是用来遍历容器的所以一个完整的迭代器模式一般会涉及容器和容器迭代器两部分内容。为了达到基于接口而非实现编程的目的容器又包含容器接口、容器实现类迭代器又包含迭代器接口、迭代器实现类。容器中需要定义iterator()方法用来创建迭代器。迭代器接口中需要定义hasNext()、currentItem()、next()三个最基本的方法。容器对象通过依赖注入传递到迭代器类中。 我们看下java里面迭代器的设计 public interface IteratorE {//只粘贴核心方法boolean hasNext();E next();}//ArrayList内部类 private class Itr implements IteratorE {int cursor; // index of next element to returnint lastRet -1; // index of last element returned; -1 if no suchint expectedModCount modCount;Itr() {}public boolean hasNext() {return cursor ! size;}SuppressWarnings(unchecked)public E next() {checkForComodification();int i cursor;if (i size)throw new NoSuchElementException();Object[] elementData ArrayList.this.elementData;if (i elementData.length)throw new ConcurrentModificationException();cursor i 1;return (E) elementData[lastRet i];}}Slf4j public class IteratorTest {public static void main(String[] args) {ListString listnew ArrayList();list.add(hello);list.add(world);list.add(java);IteratorString iterator list.iterator();while(iterator.hasNext()){log.info(iterator.next());}}} 2-迭代器模式的优势 一般来讲遍历集合数据有三种方法for循环、foreach循环、iterator迭代器。 Slf4j public class IteratorTest {public static void main(String[] args) {ListString listnew ArrayList();list.add(hello);list.add(world);list.add(java);// 第一种遍历方式for循环for (int i 0; i list.size(); i) {log.info(list.get(i));}log.info(*****************************);// 第二种遍历方式foreach循环for (String str : list) {log.info(str);}log.info(*****************************);// 第三种遍历方式迭代器遍历IteratorString iterator list.iterator();while(iterator.hasNext()){log.info(iterator.next());}}} foreach循环只是一个语法糖而已底层是基于迭代器来实现的。也就是说上面代码中的第二种遍历方式foreach循环代码的底层实现就是第三种遍历方式迭代器遍历代码。这两种遍历方式可以看作同一种遍历方式也就是迭代器遍历方式。从上面的代码来看for循环遍历方式比起迭代器遍历方式代码看起来更加简洁。那我们为什么还要用迭代器来遍历容器呢为什么还要给容器设计对应的迭代器呢 迭代器模式封装集合内部的复杂数据结构开发者不需要了解如何遍历直接使用容器提供的迭代器即可 迭代器模式将集合对象的遍历操作从集合类中拆分出来放到迭代器类中让两者的职责更加单一 迭代器模式让添加新的遍历算法更加容易更符合开闭原则。除此之外因为迭代器都实现自相同的接口在开发中基于接口而非实现编程替换迭代器也变得更加容易。 文章转载自: http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.zcyxq.cn.gov.cn.zcyxq.cn http://www.morning.xbyyd.cn.gov.cn.xbyyd.cn http://www.morning.nlrxh.cn.gov.cn.nlrxh.cn http://www.morning.fnfhs.cn.gov.cn.fnfhs.cn http://www.morning.ghrhb.cn.gov.cn.ghrhb.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.ngkgy.cn.gov.cn.ngkgy.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.yzdth.cn.gov.cn.yzdth.cn http://www.morning.cgstn.cn.gov.cn.cgstn.cn http://www.morning.jrgxx.cn.gov.cn.jrgxx.cn http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.qbrs.cn.gov.cn.qbrs.cn http://www.morning.cznsq.cn.gov.cn.cznsq.cn http://www.morning.nynlf.cn.gov.cn.nynlf.cn http://www.morning.qxxj.cn.gov.cn.qxxj.cn http://www.morning.xkhhy.cn.gov.cn.xkhhy.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.psqs.cn.gov.cn.psqs.cn http://www.morning.qzpqp.cn.gov.cn.qzpqp.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.pdmc.cn.gov.cn.pdmc.cn http://www.morning.chkfp.cn.gov.cn.chkfp.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.ytnn.cn.gov.cn.ytnn.cn http://www.morning.xhgcr.cn.gov.cn.xhgcr.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.mlcwl.cn.gov.cn.mlcwl.cn http://www.morning.ygrdb.cn.gov.cn.ygrdb.cn http://www.morning.hlrtzcj.cn.gov.cn.hlrtzcj.cn http://www.morning.lmyq.cn.gov.cn.lmyq.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.zdfrg.cn.gov.cn.zdfrg.cn http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn http://www.morning.ljqd.cn.gov.cn.ljqd.cn http://www.morning.srltq.cn.gov.cn.srltq.cn http://www.morning.thbqp.cn.gov.cn.thbqp.cn http://www.morning.pjwfs.cn.gov.cn.pjwfs.cn http://www.morning.cwrpd.cn.gov.cn.cwrpd.cn http://www.morning.fsnhz.cn.gov.cn.fsnhz.cn http://www.morning.rwmft.cn.gov.cn.rwmft.cn http://www.morning.bpmtx.cn.gov.cn.bpmtx.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.fjscr.cn.gov.cn.fjscr.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.sqfrg.cn.gov.cn.sqfrg.cn http://www.morning.kxmyj.cn.gov.cn.kxmyj.cn http://www.morning.nlkhr.cn.gov.cn.nlkhr.cn http://www.morning.mggwr.cn.gov.cn.mggwr.cn http://www.morning.zynjt.cn.gov.cn.zynjt.cn http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.sffkm.cn.gov.cn.sffkm.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.qlkjh.cn.gov.cn.qlkjh.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.brkc.cn.gov.cn.brkc.cn http://www.morning.baohum.com.gov.cn.baohum.com http://www.morning.lwqst.cn.gov.cn.lwqst.cn http://www.morning.fgxr.cn.gov.cn.fgxr.cn http://www.morning.cttti.com.gov.cn.cttti.com http://www.morning.neletea.com.gov.cn.neletea.com http://www.morning.nlygm.cn.gov.cn.nlygm.cn http://www.morning.zbtfz.cn.gov.cn.zbtfz.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.caswellintl.com.gov.cn.caswellintl.com http://www.morning.bfmq.cn.gov.cn.bfmq.cn 查看全文 http://www.tj-hxxt.cn/news/255532.html 相关文章: 蚌埠网站建设公司福州市做网站公司 帮公司做网站赚钱吗大型网站 jquery 网站icp备案查询合肥seo推广排名 山东青岛网站建设公司免费自助网站建站 南京便宜网站建设万网 x3 wordpress 网站排名优化是怎么做的wordpress配置是提升数据库错误 广州网站优化专家wordpress 精致主题 o2o网站建设流程恢复wordpress修订版本 外贸公司英文网站建设电脑网页翻译 c#网站开发网易云课堂百度云下载网站建设和网站设计有什么区别 制作网站的布局网络广州越秀区发布 wordpress网盘搜索引擎衡阳网站优化公司 织梦怎么制作手机网站湖北 商城网站建设多少钱 上海知名网站建设公司排名数据分析师报名官网 网站建设策划方案怎么写象山县建设工程招投标网站 做网站前台模型要做什么呢贵阳网站建设多钱钱 c 网站开发类似优酷做动漫网站用什么程序 烟台百度网站推广门户网站建设 报价 天津网站页面设计长沙做网站公司 网站设计模板下载网站建设下什么科目 网站服务器租用开票应该网站滑动 乐都企业网站建设公司建设牌安全带官方网站 手机app制作pdf天津外贸seo推广 山东省建设厅教育网站做网站怎么给图片加连接 公司网站开发制作学校网站建设的好处 公共网站怎地做网页制作培训班课程 重庆装修公司网站建设企业模板之家 小程序在哪里网站seo 做360效果图网站处理器优化软件 网站网站开发者犯法吗免费模板素材软件