当前位置: 首页 > 图文教程 > .Net技术 > C# > My Prototype in C#

C#
C#.Net网络程序开发-Socket篇
My Singleton in C#
My Prototype in C#
My FactoryMethod in C#
C# 编码规范和编程好习惯
C#数据库操作的三种经典用法
C#实现24点算法源代码
C#中使用GDI 让网站新闻标题个性化
Java util.concurrent中LockSupport类在C#中的实现
如何使用C#进行Visio二次开发
论C#变得越来越臃肿是不可避免的
C-Sharp开发应避免的几个小滥用
C#实现类似qq的屏幕截图程序
C#关闭电脑
用C#画树
C#从视频截图的方法
把new、virtual、override说透
关于enum应用的总结
C#修饰符总结
c#定位CUP所有问题

My Prototype in C#


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 81 ::
收藏到网摘: n/a

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