Factory模式:



Factory.h

#ifndef FACORY_H

#define FACTORY_H

class product

{

public:

product(){}

virtual ~product(){}

};

class ConcreateProduct : public Product

{

public:

ConcreateProduct();

virtual ~ConcreateProduct();

};

class Creator

{

public:

Creator(){}

virtual ~Creator(){}

void AnOperation();

protected:

virtual product *FactoryMethod()=0;


};

class ConcreateCreator :public Creator

{

public:

ConcreateCreator();

virtual ~ConcreateCreator();

protected:

virtual Product * FactoryMethod();

};

#endif


Factory.cpp

#include<Factory.h>

#include<iostream>

using namespace std;