首页 > 开发 > 综合 > 正文

My Prototype in C#

2024-07-21 02:19:38
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • //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){}
    }
    };


    上一篇:My Singleton in C#

    下一篇:My FactoryMethod in C#

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表