Prototype 模式
来源:互联网 发布:js设置style属性 编辑:程序博客网 时间:2024/05/26 22:07
CCK上说:
“必须对正在处理的对象的精确类型保持‘不知情’,并且不希望改变被克隆的原始对象,也不希望受原始对象改变的影响。”
#include <iostream>
#include <string>
using namespace std;
class Expr
{
public:
Expr(){}
Expr(const string str_,const int i):str(str_),r(i){}
Expr(const Expr& rhs):str(rhs.str),r(rhs.r){}
virtual ~Expr(){}
virtual void Initialize(const string& cstr, int cer )
{
str = cstr;
r = cer;
}
virtual Expr* new_expr()
{
return new Expr();
}
virtual Expr* clone()
{
return new Expr(*this);
}
private:
string str;
int r;
};
class Cond : public Expr
{
public:
Cond(){}
Cond(const string& ms, const int t):Expr(ms, t){};
Cond(const Cond& rth):Expr(){}
~Cond(){}
virtual void Initialize(const string& str, const int i)
{
Expr::Initialize(str, i);
cout<<"Initialize success!"<<endl;
}
Cond* new_Cond()
{
return new Cond();
}
Cond* clone()
{
return new Cond(*this);
}
};
int main()
{
Cond cond;
Cond* p = cond.new_Cond();
p->Initialize("hello",3);
Cond bcond("bird",5);
Cond* pt = bcond.clone();
delete p;
delete pt;
return 0;
}
- Prototype 模式
- prototype模式
- Prototype模式
- Prototype模式
- Prototype 模式
- Prototype 模式
- Prototype模式
- Prototype模式
- Prototype模式
- Prototype模式
- Prototype模式
- Prototype模式
- Prototype 模式
- Prototype模式
- prototype模式
- Prototype模式
- Prototype模式
- Prototype模式
- JAVA二叉查找树实现
- HibernateORM操作类..
- The USB Webcam driver in Windows CE
- Domino技术-Domino Domain Monitoring (DDM) -DDM介绍
- 开篇
- Prototype 模式
- World Wide Web Publishing Service 服务成功发送一个 停止 控件
- Byte and Bit Order Dissection(解析字节序和比特序)
- mysql过程(procedure)的使用
- 关于Visual studio .net2005 team suite中的测试功能(1)
- RMFF文件格式文档
- 支持USB Video Class的摄像头
- 通过WMI本地和远程监视网卡流量
- .net Remoting小结3