当前位置: 首页 > news >正文

云南 网站建设推广平台的方法

云南 网站建设,推广平台的方法,有赞小程序开发平台,我的世界网页版在线玩迭代器模式 介绍 设计模式定义案例迭代器模式行为型:关注对象与行为的分离 提供了一种统一的方式来访问多个不同的集合两个集合:使用了不同的数据存储方式 学生 和 警察 查询显示出集合的内容 ,使用相同的代码 问题堆积在哪里解决办法不同…

迭代器模式

介绍

设计模式定义案例
迭代器模式行为型:关注对象与行为的分离
提供了一种统一的方式来访问多个不同的集合
两个集合:使用了不同的数据存储方式
学生 和 警察

查询显示出集合的内容 ,使用相同的代码
问题堆积在哪里解决办法
不同的存储方式

统一集合查询代码
1 统一出一个存储方式
2 设计一个查询基类来统一查询代码
3 每个集合提供
  1 统一存储方式,
  2 一个查询实现(接口迭代器的实现)

类图

代码

interface BaseIterator<T>

/// <summary>
/// 迭代器基类
/// </summary>
public interface BaseIterator<T>
{// 当前T Current();// 下一个bool MoveNext();// 重新开始void Reset();
}

IteratorPolice 

using System.Collections.Generic;public class IteratorPolice : BaseIterator<People>
{// 列表List<People> listPeople = null;// 下标int currentIndex = -1;  IteratorPolice() { }public IteratorPolice(List<People> list){listPeople = list;}public People Current(){if (null == listPeople)return null;if (listPeople.Count < currentIndex)return null;return listPeople[currentIndex];}public bool MoveNext(){if (null == listPeople)return false;if (listPeople.Count > ++currentIndex)return true;return false;}public void Reset(){currentIndex = -1;}
}

IteratorStudent 


using System.Collections.Generic;public class IteratorStudent : BaseIterator<People>
{// 列表List<People> listPeople = null;// 下标int currentIndex = -1;IteratorStudent() { }public IteratorStudent(List<People> list){listPeople = list;}public People Current(){if (null == listPeople)return null;if (listPeople.Count < currentIndex)return null;return listPeople[currentIndex];}public bool MoveNext(){if (null == listPeople)return false;if (listPeople.Count > ++currentIndex)return true;return false;}public void Reset(){currentIndex = -1;}}

People


public class People
{public string name;public int age;public bool married;
}

StudentList

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class StudentList
{private List<People> list = new List<People>();private People[] studentList = new People[3];public StudentList(){People p1 = new People(){name = "WH",age = 15,married = false};studentList[0] = p1;People p2 = new People(){name = "QT",age = 16,married = false};studentList[1] = p2;People p3 = new People(){name = "YY",age = 15,married = false};studentList[2] = p3;for (int i = 0; i < studentList.Length; i++){list.Add(studentList[i]);}}public BaseIterator<People> GetIterator(){return new IteratorStudent(list);}
}

PoliceList


using System.Collections.Generic;public class PoliceList
{private List<People> list = new List<People>();public PoliceList(){People p1 = new People(){name = "WangQiang",age = 23,married = false};list.Add(p1);People p2 = new People(){name = "ZhangQiang",age = 30,married = true};list.Add(p2);People p3 = new People(){name = "LingQiang",age = 31,married = true};list.Add(p3);}public BaseIterator<People> GetIterator(){return new IteratorPolice(list); }
}

测试代码

using UnityEngine;public class TestDDQ : MonoBehaviour
{void Start(){{PoliceList pl = new PoliceList();BaseIterator<People> iterator = pl.GetIterator();while (iterator.MoveNext()){People p1 = iterator.Current();Debug.Log("姓名:" + p1.name + "   年龄:" + p1.age + "   是否结婚:" + p1.married + " ");}}Debug.Log("------------------------------------------------------------------");{StudentList pl = new StudentList();BaseIterator<People> iterator = pl.GetIterator();while (iterator.MoveNext()){People p1 = iterator.Current();Debug.Log("姓名:" + p1.name + "   年龄:" + p1.age + "   是否结婚:" + p1.married + " ");}}}
}

结果

总结

迭代器模式统一集合查询代码,以这个为目标进现优化总结出的一个经验。

还是为了更深刻的理解设计原理和优化手段。

http://www.hkea.cn/news/836666/

相关文章:

  • 顶岗实践网站开发推广管理
  • 九号公司网站优化效果
  • 模板网站建设方案北京seo排名收费
  • 做箱包关注哪个网站泰州seo平台
  • 如何给网站做流量站长工具seo
  • 桂林网站开发建设推广任务接单平台
  • 化妆品 网站建设案例seo超级外链工具免费
  • 网站建设的广告语seo自动工具
  • 有专门做市场分析的网站么太原关键词优化报价
  • 网站文化建设搜索引擎推广的常见形式有
  • wordpress分类目录消失泸州网站seo
  • 易云巢做网站公司seo入门到精通
  • 新津网站建设百度ai助手入口
  • 做学校网站什么文案容易上热门
  • 网站开发技术包括郑州网站关键词排名
  • 网站开发预算怎么算百度竞价ocpc
  • 成都锐度设计公司怎么样优化大师怎么提交作业
  • 租用网站服务器东莞市网站建设
  • 馆陶县网站网站运营管理
  • 西双版纳傣族自治州医院seo搜索优化网站推广排名
  • wordpress站点网址小吃培训2000元学6项
  • 郑州网站制作天强科技seo百度发包工具
  • 江阴市住房与建设局网站seo工资多少
  • wordpress image.php南宁百度首页优化
  • 谢家华做网站百度指数与百度搜索量
  • wordpress 安装 ubuntu整站优化代理
  • 做公司网站协议书模板下载百度竞价推广公司
  • 福田蒙派克6座二手值多少钱重庆seo点击工具
  • 有了域名 怎么做网站外贸网站推广方法之一
  • 审美网站长春网站建设路