My Prototype in C#

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//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){}

}

};

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航