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

网站开发实现电脑版和手机版的切换顺义区做网站的公司

网站开发实现电脑版和手机版的切换,顺义区做网站的公司,网站收录查询方法,wordpress 3.7 xss迭代器模式 介绍 设计模式定义案例迭代器模式行为型:关注对象与行为的分离 提供了一种统一的方式来访问多个不同的集合两个集合:使用了不同的数据存储方式 学生 和 警察 查询显示出集合的内容 ,使用相同的代码 问题堆积在哪里解决办法不同…

迭代器模式

介绍

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

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

统一集合查询代码
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.yayakq.cn/news/570628/

相关文章:

  • 做商城网站的公司网站建设鼎网络
  • 个体工商户可以申请网站建设吗制作免费企业宣传视频
  • 中电云主机怎样登入创建的网站简单html网页代码完整示范
  • 长沙网站推广公司网站建设 任务分配表
  • 深圳高端网站制作费用网站建设网络门户
  • 织梦 公司网站模板原墨网站建设
  • 企业信息化建设如何帮助客户理解网站流量胃肠科医院网站建设
  • 网站如何推广运营wordpress的函数大全
  • 中英文网站多少钱手机快速注册
  • 手机好看网站模板免费下载东莞樟木头网站建设公司
  • 石家庄做网站推广排名的公司怎么推广比较好
  • 东莞做网站平台网站怎么设置标题
  • 旅游电子商务网站建设费用济南头条新闻热点
  • 爱站网关键词挖掘查询工具那个网站教你做毕设的
  • 建一个小型的购物网站服务器一年要多少钱想接做网站的单子
  • 昆明专业做网站昌平区事业单位公共知识培训网站
  • 免费商城网站建站系统设计师网站导航
  • 襄阳网站建设营销网站开发 icon
  • 网站建设行业怎么样宣城做网站公司
  • phpcms调用网站名称wordpress怎么改搜索引擎
  • 菏泽去哪了做网站网站建设素材
  • 一起做网站逛市场佛山竞价账户托管
  • 二手车网站源码wordpress cpu负载过高
  • php公司网站微信公众平台是什么
  • 西安哪里可以做网站中国那个公司的网站做的最好
  • 网站设计需要哪些技能wordpress h5幻灯片
  • 自己的域名搭建网站网页游戏平台软件
  • 成都网站建设公司推荐嘉兴网站推广排名
  • 网站首页结构布局知名中文网站建设
  • 国外中文网站排行怎么建设网站临汾