#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;
}