My Prototype in C#

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

时间: 2024-08-17 19:56:25

My Prototype in C#的相关文章

设计模式的解析和实现(C++)之四-Prototype模式

作用: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. UML结构图: 抽象基类: 1)Prototype:虚拟基类,所有原型的基类,提供Clone接口函数 接口函数: 1)Prototype::Clone函数:纯虚函数,根据不同的派生类来实例化创建对象. 解析: Prototype模式其实就是常说的"虚拟构造函数"一个实现,C++的实现机制中并没有支持这个特性,但是通过不同派生类实现的Clone接口函数可以完成与"虚拟构造函数"同样的效果.举一个

new-js中的prototype使用的问题

问题描述 js中的prototype使用的问题 base.js var $ = function () { return new Base();} //创建一个数组,来保存获取的节点和节点数组*****************function Base() {}Base.prototype.elements = []; //创建一个数组,来保存获取的节点和节点数组****************function Base(){ this.elements = [];} //获取ID节点Base.

prototype开发者手册

  prototype.js开发者手册 对应版本1.4.0 original article by sp('Sergio Pereira') Sergio Pereira last update: March 30th 2006 中文版:THIN 最后更新:2006-3-31 其它版本English versionPDF (v1.4.0)Korean (v1.4.0)Italian (v1.4.0)Portuguese (v1.4.0)Hungarian (v1.4.0)Dutch (v1.4.

prototype 属性

  返回对象类型原型的引用. objectName.prototype objectName 参数是对象的名称. 说明 用 prototype 属性提供对象的类的一组基本功能. 对象的新实例"继承"赋予该对象原型的操作. 例如,要为 Array 对象添加返回数组中最大元素值的方法. 要完成这一点,声明该函数,将它加入 Array.prototype, 并使用它. function array_max( ){   var i, max = this[0];   for (i = 1; i

调用prototype.js的ajax进行post提交示例源码

以下是index.html:<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http

(Javascript)prototype的一个优势也是缺点

javascript  如何在Javascript实现OO编程?恐怕最好的方式就是充分利用prototype属性.关于prototype的介绍有很多,我就不赘述了.比较基本的原理是,当你用prototype编写一个类后,当你new一个新的object,浏览器会自动把prototype中的内容替你附加在object上.这样,通过利用prototype,你也就实现了类似OO的Javascript. 在Javascript中,object就是一个associative array.一个function

prototype.js常用函数和用法

函数名  解释  举例  Element.toggle  交替隐藏或显示  Element.toggle(''div1'',''div2'')  Element.hide  隐藏  Element.hide(''div1'',''div2'')  Element.show 显示  Element.show(''div1'',''div2'')  Element.remove  删除  Element.remove(''div1'',''div2'')  Element.getHeight  取得

prototype教程:使用JS接受URL参数的代码

初学prototype,发个JS接受URL参数的代码以下是HTML网页特效代码,点击运行按钮可查看效果: [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

JavaScript中的prototype(原型)属性研究

javascript 我们知道Jscript中对象的prototype属性,是用来返回对象类型原型的引用的.我们使用prototype属性提供对象的类的一组基本功能.并且对象的新实例会"继承"赋予该对象原型的操作.但是这个prototype到底是怎么实现和被管理的呢? 对于对象的prototype属性的说明,Jscript手册上如是说:所有 Jscript 内部对象都有只读的 prototype 属性.可以向其原型中动态添加功能(属性和方法),但该对象不能被赋予不同的原型.然而,用户定

AJAX之旅(1):由prototype

ajax|javascript 还是决定冠上ajax的头衔,毕竟很多人会用这个关键词搜索.虽然我认为这只是个炒作的概念,不过不得不承认ajax叫起来要方便多了.所以ajax的意思我就不详细解释了. 写这个教程的起因很简单:经过一段时间的ajax学习,有一些体会,并且越发认识到ajax技术的强大,所以决定记录下来,顺便也是对自己思路的整理.有关这个教程的后续,请关注http://www.x2design.net 前几年,javascript在一般人眼里,功能还很狭窄,所能做的要么是一些简单的表单验