日期:2008-09-22  浏览次数:20366 次

//MyPrototype
using System;
using System.Collections;
//abstract PageStylePrototype Class 'Prototype
abstract class PageStylePrototype
{
//Fields
protected string stylestring;
//Properties
public string StyleString
{
get{return stylestring;}
set{stylestring=value;}
}
//Methods
abstract public PageStylePrototype Clone();
};
//---PageStyle Class---
class PageStyle:PageStylePrototype
{
//Constructor
public PageStyle(String stylestr)
{
StyleString=stylestr;
}
override public PageStylePrototype Clone()
{
return (PageStylePrototype)this.MemberwiseClone();
}

public void DisplayStyle()
{
Console.WriteLine(StyleString);
}

};
//--------------------------------------------End of Style Class
//StyleManager Class
class StyleManager
{
//Fields
protected Hashtable styleht=new Hashtable();
protected PageStylePrototype styleref;

//Constructors
public StyleManager()
{
styleref=new PageStyle("thefirststyle");
styleht.Add("style1",styleref);

styleref=new PageStyle("thesecondstyle");
styleht.Add("style2",styleref);

styleref=new PageStyle("thethirdstyle");
styleht.Add("style3",styleref);
}

//Indexers
public PageStylePrototype this[string key]
{
get{ return (PageStylePrototype)styleht[key];}
set{ styleht.Add(key,value);}
}
};
//--------------------------------------------End of StyleManager Class
//TestApp
class TestApp
{
public static void Main(string[] args)
{
StyleManager stylemanager =new StyleManager();

PageStyle stylea =(PageStyle)stylemanager["style1"].Clone();
PageStyle styleb =(PageStyle)stylemanager["style2"].Clone();
PageStyle stylec =(PageStyle)stylemanager["style3"].Clone();

stylemanager["style4"]=new PageStyle("theforthstyle");

PageStyle styled =(PageStyle)stylemanager["style4"].Clone();

stylea.DisplayStyle();
styleb.DisplayStyle();
stylec.DisplayStyle();
styled.DisplayStyle();

while(true){}
}
};