《大话设计模式》-- 8.原型模式
来源:互联网 发布:蓝牙耳机生产测试软件 编辑:程序博客网 时间:2024/06/07 06:45
原型模式:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。
原型模式其实就是从一个对象再创建另外一个可定制的对象,而且不需要知道任何创建的细节
Prototype,原型类 class Prototype{private: string id;public: Prototype (string id) { this->id = id; } string GetID() { return id; } //抽象类关键就是有这样一个Clone方法 virtual Prototype Clone() = 0;}; 具体原型类 class ConcretePrototype1 : public Prototype{public: ConcretePrototype1(string id):Prototype(id) { } ConcretePrototype1(const ConcretePrototype1 &other) { //深拷贝 } virtual ConcretePrototype1* Clone() { return new ConcretePrototype1(*this); }} 客户端代码 void main(){ ConcretePrototype1 *p1 = new ConcretePrototype1("I"); ConcretePrototype1 *c1 = p1->Clone(); cout << c1->GetID << endl;}
0 0
- 《大话设计模式》-- 8.原型模式
- 大话设计模式--原型模式
- 大话设计模式-原型模式
- 大话设计模式-原型模式
- 大话设计模式-原型模式
- 大话设计模式----原型模式
- 大话设计之原型模式
- 大话设计模式_原型模式
- 大话设计模式之原型模式
- 大话设计模式之原型模式
- 大话设计模式之原型模式
- 【大话设计模式】—— 原型模式
- 大话设计模式之原型模式
- 大话设计模式—原型模式
- 大话设计模式c++实现--原型模式
- 大话设计模式09----原型模式
- java设计模式大话之原型模式
- 大话设计模式读后感之原型模式
- Hibernate one-to-many many-to-one 的配置
- 关于IOS7下navigation title 文字黑色的
- Surrounded Regions
- struts2+spring+mybatis入门教程五之配置log4j
- 《大话设计模式》-- 7.工厂方法模式
- 《大话设计模式》-- 8.原型模式
- 看一眼哈佛 你就会明白自己到底缺什么?
- 开篇记录
- 《大话设计模式》-- 9.模板方法模式
- 画图解释SQL联合语句
- Oracle之Chr函数返回
- 黑马程序员——学习笔记18.Java注解
- 在Windows下编译OpenSSL
- 《大话设计模式》-- 10.迪米特法则