迭代器模式:将遍历集合的任务交给一个叫做迭代器的对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构*/
来源:互联网 发布:ubuntu显示隐藏文件 编辑:程序博客网 时间:2024/06/05 15:35
<!-- 迭代器:是遍历集合的成熟模式-->
<?php
/*
迭代器模式:将遍历集合的任务交给一个叫做迭代器的对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构*/
interface Iterators{
public function First();
public function Pre();
public function Next();
public function End();
public function CurrentItem();
}
?>
<?php
require_once "Iterators.php";
class Iteratorobj implements Iterators{
public $objects;
public $current = 0;
public function __construct($objects)
{
$this->objects = $objects;
}
public function First()
{
return $this->objects[0];
}
public function Pre()
{
$this->current--;
if($this->current < 0 ){
return false;
}else{
return $this->objects[$this->current];
}
}
public function Next()
{
$this->current++;
if($this->current <= count($this->objects))
{
return $this->objects[$this->current];
}
return false;
}
public function End()
{
return $this->objects[count($this->objects)-1];
}
public function CurrentItem()
{
return $this->objects[$this->current];
}
}
?>
<?php
require_once "Iteratorobj.php";
$arr = array('hello',"world","say");
$obj = new Iteratorobj($arr);
echo $obj->First()."<br>";
echo $obj->End()."<br>";
echo $obj->Next()."<br>";
?>
<?php
/*
迭代器模式:将遍历集合的任务交给一个叫做迭代器的对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构*/
interface Iterators{
public function First();
public function Pre();
public function Next();
public function End();
public function CurrentItem();
}
?>
<?php
require_once "Iterators.php";
class Iteratorobj implements Iterators{
public $objects;
public $current = 0;
public function __construct($objects)
{
$this->objects = $objects;
}
public function First()
{
return $this->objects[0];
}
public function Pre()
{
$this->current--;
if($this->current < 0 ){
return false;
}else{
return $this->objects[$this->current];
}
}
public function Next()
{
$this->current++;
if($this->current <= count($this->objects))
{
return $this->objects[$this->current];
}
return false;
}
public function End()
{
return $this->objects[count($this->objects)-1];
}
public function CurrentItem()
{
return $this->objects[$this->current];
}
}
?>
<?php
require_once "Iteratorobj.php";
$arr = array('hello',"world","say");
$obj = new Iteratorobj($arr);
echo $obj->First()."<br>";
echo $obj->End()."<br>";
echo $obj->Next()."<br>";
?>
阅读全文
0 0
- 迭代器模式:将遍历集合的任务交给一个叫做迭代器的对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构*/
- <c:forEach 遍历集合中的集合的对象属性参数
- javascript中遍历对象的List集合
- Java中对象集合的序列化
- 集合框架_集合的遍历之迭代器遍历
- 完成序列化和反序列化的一个集合操作,集合对象中要求保存2个用户对象
- JAVA集合-集合的遍历
- 已知二叉树后序遍历序列是DBCEFGHA,中序遍历序列EDCBAHFG,它的前序遍历的序列是?
- 已知二叉树后序遍历序列是DBCEFGHA,中序遍历序列EDCBAHFG,它的前序遍历的序列是?
- 将"先竖后横"的遍历序列转化为"先横后竖"的遍历
- ASP中遍历和操作Application对象的集合
- ASP中遍历和操作Application对象的集合
- java中List对象集合的遍历方法
- JQuery对象集合的四种遍历方式
- Json中遍历对象或者集合,简单的实现
- Mybatis的Mapper.xml文件中如何遍历一个对象的集合属性
- 遍历集合的方法
- JavaMap集合的遍历
- 装饰器:动态修改类的功能
- mybatis自增主键设置
- eclipse下面的工程打包,放到linux运行
- nyoj 914 Yougth的最大化
- MD5加密
- 迭代器模式:将遍历集合的任务交给一个叫做迭代器的对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构*/
- 2017.7.27 计算机编程培训第二天
- 安卓开发 轮播图Banner+缩放PhotoView
- 生成器【建造者】模式:将一个复杂对象的构造与它的表示分离
- 文章标题
- 我与某大型中药企业之间不得不说的事
- 一篇文章搞懂字符集编码
- 详解sqlnet.ora的作用
- java 关于Spring中Aop的简单理解以及SpringBoot如何添加Aop实现步骤