C ++ 抽象工厂模型
来源:互联网 发布:淘宝店铺营销亮点 编辑:程序博客网 时间:2024/06/08 15:56
#include "stdafx.h"#include <iostream>#include <string>using namespace std; /////////////产品class CLinux{public: virtual ~CLinux() {}; //产品使用公共接口 virtual void Start() = 0;}; class CLinuxMobile : public CLinux{public: CLinuxMobile() { cout << "create linux mobile." << endl; } virtual ~CLinuxMobile() {}; virtual void Start() { cout << "linux mobile start." << endl; };};class CLinuxPC : public CLinux{public: CLinuxPC() { cout << "create linux PC." << endl; } virtual ~CLinuxPC() {}; virtual void Start() { cout << "linux PC start." << endl; };};class CWindows{public: virtual ~CWindows() {}; //产品使用公共接口 virtual void Start() = 0;}; class CWindowsMobile : public CWindows{public: CWindowsMobile() { cout << "create windows mobile." << endl; } virtual ~CWindowsMobile() {}; virtual void Start() { cout << "windows mobile start." << endl; };};class CWindowsPC : public CWindows{public: CWindowsPC() { cout << "create windows PC." << endl; } virtual ~CWindowsPC() {}; virtual void Start() { cout << "windows PC start." << endl; };}; ////工厂class CFactory{public: virtual ~CFactory(){}; //产品族有个产品组件 virtual CLinux* CreateLinux() = 0; virtual CWindows* CreateWindows() = 0;}; class CMobileFactory : public CFactory{public: CMobileFactory() { cout << "create mobile factory." << endl; } virtual ~CMobileFactory(){}; virtual CLinux* CreateLinux() { return new CLinuxMobile; }; virtual CWindows* CreateWindows() { return new CWindowsMobile; };}; class CPCFactory : public CFactory{public: CPCFactory() { cout << "create PC factory." << endl; } virtual ~CPCFactory(){}; virtual CLinux* CreateLinux() { return new CLinuxPC; }; virtual CWindows* CreateWindows() { return new CWindowsPC; };}; void Test(CFactory* pFactory){ CLinux* pLinux = NULL; CWindows* pWindows = NULL; pLinux = pFactory->CreateLinux(); pWindows = pFactory->CreateWindows(); pLinux->Start(); pWindows->Start(); delete pWindows; delete pLinux;}; int main(){ CFactory* pFactory = NULL; //手机工厂。生产手机产品族,种类有Linux和Windows pFactory = new CMobileFactory; Test(pFactory); delete pFactory; cout << endl; //PC工厂。生产PC产品族,种类有Linux和Windows pFactory= new CPCFactory; Test(pFactory); delete pFactory; system("pause"); return 0;}
0 0
- C ++ 抽象工厂模型
- 抽象工厂(C++)
- 抽象工厂(C++)
- 【C++】Chapter11:抽象工厂模式
- Objective C--抽象工厂模式
- Objective C 抽象工厂模式
- 抽象工厂模式(C#)
- Objective C--抽象工厂模式
- 抽象工厂模式实例(C#)
- C语言实现抽象工厂模式实例
- 抽象工厂模式 (C语言实现)
- C#--抽象工厂设计模式原理
- C#--抽象工厂设计模式--三层框架
- 数据库连接工厂 - 抽象工厂的应用(C#)
- 数据库连接工厂 - 抽象工厂的应用(C#)
- C语言设计模式:工厂和抽象工厂
- C++:浅谈工厂模式与抽象工厂模式
- 设计模式利剑三--抽象工厂方法模型
- 【基于WinForm+Access局域网共享数据库的项目总结】之篇二:WinForm开发扇形图统计和Excel数据导出
- 看操作系统虚拟化原理总结篇——虚拟化概述原理
- Maven查找使用的包
- iphone手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognizer
- opencv 图片基本处理(灰度化,反色,二值化,膨胀腐蚀以及ROI的copy等)
- C ++ 抽象工厂模型
- UVa989 - Su Doku(数独游戏)
- c 函数指针
- Android 开发指导文档(译)-- Bound Services
- 空间大地测量与GPS导航定位时间系统相互转换,格里高利时通用时儒略日,GPS时,年积日相互转换
- BCB操作注册表
- 程序猿进化史——分解数字
- 基于RFID的智能旅游CY-RAT-101/102游客管理系统
- 转载的