⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractfactory.h

📁 设计模式for c++ abstractfactory
💻 H
字号:
/**
 * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -