Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1061669
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类: 项目管理

2010-03-04 23:49:43

代码片断1:Product.h //Product.h
#ifndef _PRODUCT_H_
#define _PRODUCT_H_

class Product
 {
public:
    virtual ~Product() =0;
    protected: Product();
};


class ConcreteProduct: public   Product
 {
 public:
    ConcreteProduct();
    ~ConcreteProduct();
};
#endif //~_PRODUCT_H_


//==============================
代码片断2:Product.cpp //Product.cpp
#include "Product.h"
#include
using namespace std;

Product::Product()
 {
 }

Product::~Product()
{
}

ConcreteProduct::ConcreteProduct()
{
    cout<<"ConcreteProduct...."<}

ConcreteProduct::~ConcreteProduct()
{
}

//=============================
代码片断3:Factory.h //Factory.h
#ifndef _FACTORY_H_
#define _FACTORY_H_

class Product;

class Factory
{
public:
    virtual ~Factory() = 0;
    virtual Product* CreateProduct() = 0;
protected:
    Factory();
private:
};


class ConcreteFactory:public Factory
{
public:
     ~ConcreteFactory();
     ConcreteFactory();
     Product* CreateProduct();

protected:
private:
};
#endif //~_FACTORY_H_


//================================
代码片断4:Factory.cpp //Factory.cpp
#include "Factory.h"
#include "Product.h"
#include

using namespace std;

Factory::Factory()
{
}

Factory::~Factory()
{
}

ConcreteFactory::ConcreteFactory()

      cout << "ConcreteFactory....." << endl;
}

ConcreteFactory::~ConcreteFactory()
{
}

Product* ConcreteFactory::CreateProduct()
{
    return new ConcreteProduct();
}

//===============================
代码片断5:main.cpp //main.cpp

#include "Factory.h"
#include "Product.h"
#include

using namespace std;

int main(int argc,char* argv[])
{
      Factory *fac = new ConcreteFactory();
      Product *p = fac->CreateProduct();
      return 0;
}


阅读(1336) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~