Design Pattern ->Prototype
Layering & Contract Philosophy With additional indirection
Prototype

The example code is as following:
class CObject
{
public:
virtual CObject* clone() const = ;
virtual void BasicOperation() = ;
}
//clone is a virtual method, its return type can be different from base class
class CConcreteObject: public CObject
{
public:
virtual CConcreteObject* clone() const { return new CConcreteObject (*this);}
} class Client
{
public: CObject* pObject = NULL;
public:
void setObject(CObject *p)
{
if (pObject != NULL )
delete pObject;
pObject = NULL;
pObject = p->clone();
}
void operation() { pObject->BasicOperation();}
}
Applicability
- Use the Prototype pattern when:a system should be independent of how its products are created, composed, and represented;
- Use the Prototype pattern when: the classes to instantiate are specified at run-time, for example, by dynamic loading; or to avoid building a class hierarchy of factories that parallels the class hierarchy of products; or when instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually,each time with the appropriate state.
Participants
- Prototype (Graphic): declares an interface for cloning itself which must be implemented by derived class.
- ConcretePrototype (Staff, WholeNote, HalfNote): implements an operation for cloning itself.
- Client (GraphicTool): creates a new object by asking a prototype to clone itself.
Collaborations
- A client asks a prototype to clone itself and manipulates them as own.
From:Design Patterns:Elements of Reusable Object-Oriented Software, by GoF
Design Pattern ->Prototype的更多相关文章
- Design Pattern —— Prototype /Template Method/Iterator/Composite/Bridge
Prototype /Template Method/Iterator/Composite/Bridge 为什么把这五种设计模式放一起呢,没什么太高大上的原因,就是因为这五种模式JAVA开发最基本的特 ...
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- design pattern及其使用
什么是设计模式? design pattern是一个通用的,可以被重用的关于一个常见的问题的解决方案. 为什么要用设计模式? 引入设计模式的理论基础非常简单.我们每天都会碰到问题.我们可能碰到决定使用 ...
- C++ Design Pattern: What is a Design Pattern?
Q: What is a Design Pattern? A: Design Patterns represent solutions to problems what arise when deve ...
- Design Pattern in Simple Examples
Instead of defining what is design pattern lets define what we mean by design and what we mean by pa ...
- java设计模式大全 Design pattern samples in Java(最经典最全的资料)
java设计模式大全 Design pattern samples in Java(最经典最全的资料) 2015年06月19日 13:10:58 阅读数:11100 Design pattern sa ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
随机推荐
- 牛客nowcoder NOIP普及组第三场
qtmd AK了 直接题解吧 题目链接 A-十七边形 牛牛想在一个半径为r的圆中,找到一个内接的十七边形,使他的面积最大.输入半径r,输出最大的面积. 1 <= r <= 10000 在1 ...
- 再谈hive-1.0.0与hive-1.2.1到JDBC编程忽略细节问题
不多说,直接上干货,这个问题一直迷惑已久,今天得到亲身醒悟. 所以,建议hadoop-2.6.0.tar.gz的用户与hive-1.0.0搭配使用.当然,也可以去用高版本去覆盖它. log4j:WAR ...
- mysql不支持emoji表情的问题的解决方法
最近财神圈项目集成微信登录功能的过程中,当保存用户有昵称含有表情符号时后台服务抛出异常,原来是数据库默认字符集不支持emoji表情字符.找到问题的原因后,因为之前也没有遇到过这样的问题,也没思路,迅速 ...
- .netcore在linux下使用P/invoke方式调用linux动态库
http://www.mamicode.com/info-detail-2358309.html .netcore下已经实现了通过p/invoke方式调用linux的动态链接库(*.so)文件 1 ...
- web前端开发道路
https://github.com/z-jingjie/developer-roadmap-zh-CN
- 关于box-shadow、border-radius不兼容ie8的解决办法
本来从css3兼容ie9+挺好的,可是总有一些共识要求ie8+,于是就有了我们的苦逼的找解决办法.之前在网上查到一些说用 PIE.htc. But 我就是按照他说的写的没有管用.请教了一下别人才会写了 ...
- Robot Framework 的安装和配置
Robot Framework 的安装和配置 在使用 RF(Rebot framework)的时候需要 Python 或 Jython 环境,具体可根据自己的需求来确定.本文以在有 Python 的环 ...
- oracle merge into函数中插入clob字段
当使用Merge into 函数向ORACLE数据库中插入或更新数据时,报错“ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值”,使用如下方法可以把String转换为clob. 需 ...
- java生成复杂word文档
在Web应用中,有时需要按照固定的模板将数据导出到Word,如流程审批单,在流程处理完成后将处理过程按照流程单的要求导出,有时程序中需要实现生成 标准Word文档,要求能够打印,并且保持页面样式不变, ...
- vue vue-resource网络请求
在使用get/post 网络请求,需要下载插件 "vue-resource" npm install vue-resource -s 在路由要导入及注册 import Vue fr ...