设计模式复习-原型模式
生活随笔
收集整理的這篇文章主要介紹了
设计模式复习-原型模式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#pragma once
#include "stdafx.h"
#include<string>
#include<iostream>
#include<windows.h>
using namespace std;#pragma warning(disable:4996)//原型模式 Prototype (Clone模式) 比較簡單,就是實現深復制class PrototypeInterface {
public:virtual PrototypeInterface * Clone() = 0;virtual VOID Show() = 0;
};class Body :public PrototypeInterface {
private:char mcCache[100] = {0};public:VOID SetKey(char cCache[]) {strcpy(mcCache , cCache);}VOID Show() {cout << mcCache << endl;}PrototypeInterface * Clone() {Body *pBody = new Body();pBody->SetKey(mcCache);return pBody;}
};int main()
{Body * pBody = new Body();pBody->SetKey("123");pBody->Show();PrototypeInterface *pPrototypeInterface = pBody->Clone();pPrototypeInterface->Show();delete pBody;delete pPrototypeInterface;getchar();return 0;
}
?
總結
以上是生活随笔為你收集整理的设计模式复习-原型模式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式复习-代理模式
- 下一篇: 设计模式复习-模板方法模式