ICollection
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Iterator
{
/**//// <summary>
/// 集合接口(Aggregate)
/// </summary>
public interface ICollection
{
/**//// <summary>
/// 創建迭代器對象
/// </summary>
/// <returns></returns>
IIterator CreateIterator();
}
}
Collection
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Iterator
{
/**//// <summary>
/// 集合(ConcreteAggregate)
/// </summary>
public class Collection : ICollection
{
private List<MessageModel> list = new List<MessageModel>();
/**//// <summary>
/// 創建迭代器對象
/// </summary>
/// <returns></returns>
public IIterator CreateIterator()
{
return new Iterator(this);
}
/**//// <summary>
/// 集合內的對象總數
/// </summary>
public int Count
{
get { return list.Count; }
}
/**//// <summary>
/// 索引器
/// </summary>
/// <param name="index">index</param>
/// <returns></returns>
public MessageModel this[int index]
{
get { return list[index]; }
set { list.Add(value); }
}
}
}