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)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
随机推荐
- P1527 [国家集训队]矩阵乘法
\(\color{#0066ff}{ 题目描述 }\) 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. \(\color{#0066ff}{输入格式}\) 第一行两个数N,Q ...
- 拓扑排序+数学+DP【洛谷P1685】 游览
P1685 游览 题目描述 顺利通过了黄药师的考验,下面就可以尽情游览桃花岛了! 你要从桃花岛的西头开始一直玩到东头,然后在东头的码头离开.可是当你游玩了一次后,发现桃花岛的景色实在是非常的美丽!!! ...
- __weak 和 __strong 还有Autorelease的用法
使用容器的block版本的枚举器时,内部会自动添加一个AutoreleasePool: Autorelease对象是在当前的runloop迭代结束时释放的,而它能够释放的原因是系统在每个runloop ...
- .NET Services Stack笔记之手写版
- vue.js路由嵌套
<!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...
- Django 12 中间件、上下文处理器和admin后台
Django 12 中间件.上下文处理器和admin后台 一.中间件 #Django中间件 (Middleware) # 一个轻量级.底层的“插件”系统,可以介入Django的请求和响应处理过程,修改 ...
- kibana启动调试
在windows的命令行窗口中,将路径制定到kibana的源代码bin目录中,然后执行 kibana.bat --dev --no-base-path 需要注意的是kibana.yml中的配置文件需要 ...
- Python入门字符编码
计算机基础知识 一.应用程序任何操作硬件的请求都需要向操作系统发起系统调用,然后由操作系统去操作硬件 二.文本编辑器存取文件的原理 1.打开编辑器就打开了启动了一个进程,是在内存中的,所以,用编辑器编 ...
- Windows 常见DOS命令
1. 查看网络连接及路由状况 netstat -a 查看开启了哪些端口,常用netstat -an netstat -n 查看端口的网 ...
- Install NGINX, PHP-FPM (5.6) on CentOS 6
Installing NGINX with PHP on CentOS 6 can be a hassle depending on the install and packages you use. ...