工厂模式-c++实现

// factorypattern.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;


class IProduct
{
public:
	IProduct() {};
	virtual ~IProduct() {};

};

class IPhone :public IProduct
{
public:
	IPhone() {};
	virtual ~IPhone() {};

};

class IPad : public IProduct
{
public:
	IPad() {};
	virtual ~IPad() {};
};


class IFactory
{
public:
	IFactory() {};
	virtual ~IFactory(void) {};
	virtual IProduct* getProduct() = 0;
};

class IPadFactory : public IFactory
{
public:
	IPadFactory() {};
	virtual ~IPadFactory() {};
	virtual IProduct* getProduct()
	{		
		return new IPad();
	}

};

class IPhoneFactory :public IFactory
{
public:
	IPhoneFactory() {};
	virtual ~IPhoneFactory() {};
	virtual IProduct *getProduct()
	{
		return new IPhone();
	}
};

int main()
{
	IFactory *pFac;
	IProduct *pPro;
    
	pFac = new IPadFactory();
	pPro = pFac->getProduct();

	pFac = new IPhoneFactory();
	pPro = pFac->getProduct();

	delete pFac;
	pFac = NULL;
    
	delete pPro;
	pPro = NULL;
    return 0;
}

Linux Administration: A Beginner's Guide, Fifth Edition Paperback: 662 pages Publisher: McGraw-Hill Osborne Media; 5 edition (September 23, 2008) Language: English ISBN-10: 0071545883 ISBN-13: 978-0071545884 Format: PDF You can buy this book: Amazon.com Description: Administering a Linux system isn't much like administering a Windows machine. Though the goals are similar and comparable problems arise under both environments, they each require administrators to adopt a certain way of thinking about processes and data. Linux Administration: A Beginner's Guide helps readers adapt their Windows experience to Linux work. Author Steve Shah does a great job of clueing Linux newcomers into the environment. His explanations are clear, patient, accurate, and useful, and they cover all aspects of the system administrator's job. He's careful to explain hundreds of commands in a logical way, including lists of options and examples of typical uses in many cases. But this is no mere command reference or novice's introduction. Shah doesn't shy away from explaining the really interesting aspects of Linux administration, including kernel compilation, Domain Name Service (DNS) configuration, sendmail setup, and establishing firewall protection with IP chaining. For all of these subjects (and many more), this book includes clear statements of what concepts are relevant, which commands to issue, and what to expect in response. It's a great help in self-guided explorations. It's also worth having this book on hand for work assignments--you'll find complete recipes for configuring all major Internet and local area network (LAN) services that also take into account easy maintenance and security.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值