abstractfactory.h

来自「设计模式for c++ abstractfactory」· C头文件 代码 · 共 116 行

H
116
字号
/**
 * abstractfactory.h
 * Implemented by Blueprint Technologies, Inc.
 */

#ifndef _abstractfactory_h
#define _abstractfactory_h

/**
 * declares an interface for a type of product object.
 */

class AbstractProductA
{
};

/**
 * defines a product object to be created by the 
 * corresponding concrete factory.
 */

class ProductA1: public AbstractProductA
{
};

/**
 * defines a product object to be created by the 
 * corresponding concrete factory.
 */

class ProductA2: public AbstractProductA
{
};

/**
 * declares an interface for a type of product object.
 */

class AbstractProductB
{
};

/**
 * defines a product object to be created by the 
 * corresponding concrete factory.
 */

class ProductB1: public AbstractProductB
{
};

/**
 * defines a product object to be created by the 
 * corresponding concrete factory.
 */

class ProductB2: public AbstractProductB
{
};

/**
 * declares an interface for operations that create
 * abstract product objects.
 */

class AbstractFactory
{

public:
	virtual AbstractProductA* createProductA() = 0;
	virtual AbstractProductB* createProductB() = 0;
	
};

/**
 * implements the operations to create concrete
 * product objects.
 */

class ConcreteFactory1: public AbstractFactory
{

public:
	virtual AbstractProductA* createProductA()
	{
		return new ProductA1();
	};

	virtual AbstractProductB* createProductB()
	{
		return new ProductB1();
	};
};

/**
 * implements the operations to create concrete
 * product objects.
 */

class ConcreteFactory2: public AbstractFactory
{

public:
	virtual AbstractProductA* createProductA()
	{
		return new ProductA2();
	};

	virtual AbstractProductB* createProductB()
	{
		return new ProductB2();
	};
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?