原型模式
来源:互联网 发布:mac装win7未能启动 编辑:程序博客网 时间:2024/05/20 03:07
原型模式是在原有的对象上克隆新的对象
原型模式的构成
1.抽象原型类(定义具有克隆自己的方法)
2.具体原型类(实现定义的方法)
3.客户类(克隆生成生的对象)
abstract class BaseProtype//抽象
{ public string ID { get; set; } public abstract BaseProtype Cellon(); public abstract string Hello(); }
{ public override BaseProtype Cellon() {//实现定义方法 return (BaseProtype)MemberwiseClone(); } public override string Hello() { return ID; } }
{//客户类调用 BaseProtype b1 = new ProType(); b1.ID = "123456"; BaseProtype b2 = b1.Cellon(); b2.ID = "ABCDEFG"; MessageBox.Show(b1.Hello() + "\r\n" + b2.Hello()); }//下面是结果
阅读全文
0 0
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型 模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- 原型模式
- Shiro身份验证
- Git 入门
- 二分查找
- Unity3D 之 console面板的停靠
- 源码阅读SourceInsight
- 原型模式
- linux 自定义全局环境变量设置
- 坑
- HDU 6105 Gameia【思维+博弈】
- CSU 1803: 2016 (省赛真题)
- 【c++】基本数据类型
- npoi导出超过65000行excel分sheet页。
- 【字符串入门专题1】【hdu4763】【未ac题】【扩展kmp exkmp】
- Python 井字棋