zoukankan      html  css  js  c++  java
  • Prototype Pattern

    prototype 模式结构图:

    实现:

     1 #ifndef _PROTOTYPE_H_
     2 #define _PROTOTYPE_H_
     3 
     4 class Prototype
     5 {
     6 public:
     7     virtual ~Prototype();
     8     virtual Prototype* Clone() const = 0;
     9 
    10 protected:
    11     Prototype();
    12 
    13 private:
    14 };
    15 
    16 class ConcretePrototype:public Prototype
    17 {
    18 public:
    19     ConcretePrototype();
    20     ConcretePrototype(const ConcretePrototype& cp);
    21     ~ConcretePrototype();
    22     Prototype* Clone()const;
    23 protected:
    24 private:
    25 };
    26 
    27 #endif
    Prototype.h
     1 #include "Prototype.h"
     2 #include <iostream>
     3 using namespace std;
     4 
     5 Prototype::Prototype()
     6 {
     7 
     8 }
     9 Prototype::~Prototype()
    10 {
    11 
    12 }
    13 Prototype* Prototype::Clone()const
    14 {
    15     return 0;
    16 }
    17 ConcretePrototype::ConcretePrototype()
    18 {
    19 
    20 };
    21 ConcretePrototype::~ConcretePrototype()
    22 {
    23 
    24 }
    25 ConcretePrototype::ConcretePrototype(const ConcretePrototype& cp)
    26 {
    27     cout<<"ConcretePrototype copy..."<<endl;
    28 }
    29 Prototype* ConcretePrototype::Clone()const
    30 {
    31     return new ConcretePrototype(*this);
    32 }
    Prototype.cpp
  • 相关阅读:
    37 图的存储结构
    hdu 1272 使用set和并查集
    题目数据输入中间读入字符
    第六篇 模块基础
    第十二章 并发编程
    并发编程(四)
    第五篇 函数进阶
    第四篇 函数基础
    并发编程(三)
    并发编程(二)
  • 原文地址:https://www.cnblogs.com/programmer-wfq/p/4649189.html
Copyright © 2011-2022 走看看