RssEntry类的完整声明如下。注意其中的静态方法CreateNew(),用来根据提要的标题和URL创建一个新的RssEntry对象,该对象的Id属性由CreateNew()方法负责维护,以便保证唯一性:
图11-6 RssEntry类的类图
public class RssEntry
{
private static int nextId = 0;
/// <summary>
/// 根据标题和URL创建新的RssEntry对象。
/// </summary>
/// <param name="title">标题</param>
/// <param name="url">URL</param>
/// <returns>新的RssEntry对象</returns>
public static RssEntry CreateNew(string title, string url)
{
RssEntry newEntry = new RssEntry();
newEntry.Id = nextId++;
newEntry.Title = title;
newEntry.Url = url;
return newEntry;
}
private int m_id;
public int Id
{
get { return m_id; }
set { m_id = value; }
}
private string m_title;
public string Title
{
get { return m_title; }
set { m_title = value; }
}
private string m_url;
public string Url
{
get { return m_url; }
set { m_url = value; }
}
public RssEntry()
{
}
}