LN : Eden Polymorphic And OOP Design Pattern Abstract Factory
- Appreciation to our TA, +7, who designed this task.
Client.cpp
#include <iostream>
#include <string>
#include "Factory.hpp"
#include "Product.hpp"
int main() {
UIFactory* ui = 0;
int choose;
std::cin >> choose;
switch (choose) {
case 0:
ui = new MFCUIFactory();
break;
case 1:
ui = new GtkUIFactory();
break;
case 2:
default:
ui = new QtUIFactory();
}
/* Use the factory to build interface. */
Window* toolbox = ui->getToolboxWindow();
Window* layers = ui->getLayersWindow();
Window* main = ui->getMainWindow();
/* See what have we recieved. */
std::cout << toolbox->getToolkit() << ":" << toolbox->getType() << std::endl;
std::cout << layers->getToolkit() << ":" << layers->getType() << std::endl;
std::cout << main->getToolkit() << ":" << main->getType() << std::endl;
ui->deleteWindow(toolbox);
ui->deleteWindow(layers);
ui->deleteWindow(main);
delete ui;
}
Product.hpp
#ifndef PRODUCT_HPP
#define PRODUCT_HPP
#include <iostream>
#include <string>
using namespace std;
class Window {
public:
virtual string getToolkit() = 0;
virtual string getType() = 0;
string kit;
};
class ToolboxWindow:public Window {
public:
ToolboxWindow(string a) {
kit = a;
}
virtual string getToolkit() {
return kit;
}
virtual string getType() {
return "ToolboxWindow";
}
};
class LayersWindow:public Window {
public:
LayersWindow(string a) {
kit = a;
}
virtual string getToolkit() {
return kit;
}
virtual string getType() {
return "LayersWindow";
}
};
class MainWindow:public Window {
public:
MainWindow(string a) {
kit = a;
}
virtual string getToolkit() {
return kit;
}
virtual string getType() {
return "MainWindow";
}
};
#endif
Factory.hpp
#ifndef FACTORY_HPP
#define FACTORY_HPP
#include <iostream>
#include <string>
#include "Product.hpp"
using namespace std;
class UIFactory {
public:
virtual Window* getToolboxWindow() = 0;
virtual Window* getLayersWindow() = 0;
virtual Window* getMainWindow() = 0;
virtual void deleteWindow(Window* a) = 0;
};
class MFCUIFactory:public UIFactory {
public:
MFCUIFactory() {}
virtual Window* getToolboxWindow() {
return new ToolboxWindow("MFC");
}
virtual Window* getLayersWindow() {
return new LayersWindow("MFC");
}
virtual Window* getMainWindow() {
return new MainWindow("MFC");
}
virtual void deleteWindow(Window* a) {
delete a;
}
};
class GtkUIFactory:public UIFactory {
public :
GtkUIFactory() {}
virtual Window* getToolboxWindow() {
return new ToolboxWindow("Gtk");
}
virtual Window* getLayersWindow() {
return new LayersWindow("Gtk");
}
virtual Window* getMainWindow() {
return new MainWindow("Gtk");
}
virtual void deleteWindow(Window* a) {
delete a;
}
};
class QtUIFactory:public UIFactory {
public:
QtUIFactory() {}
virtual Window* getToolboxWindow() {
return new ToolboxWindow("Qt");
}
virtual Window* getLayersWindow() {
return new LayersWindow("Qt");
}
virtual Window* getMainWindow() {
return new MainWindow("Qt");
}
virtual void deleteWindow(Window* a) {
delete a;
}
};
#endif
LN : Eden Polymorphic And OOP Design Pattern Abstract Factory的更多相关文章
- Design Pattern ->Abstract Factory
Layering & Contract Philosophy With additional indirection Abstract Factory //The example code i ...
- [design pattern](5) Factory Method
前言 在前面一章博主介绍了简单工厂模式(Simple Factory),接着上面的章节,今天博主就来介绍下工厂方法模式(Factory Method). 思考题 首先,让我们来思考下面的问题: 在上一 ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- 简单工厂设计模式(Simple Factory Design Pattern)
[引言]最近在Youtub上面看到一个讲解.net设计模式的视频,其中作者的一个理解让我印象很深刻:所谓的设计模式其实就是运用面向对象编程的思想来解决平时代码中的紧耦合,低扩展的问题.另外一点比较有见 ...
- Design Pattern ——Factory Method&Abstract Factory
今天开始复习设计模式.设计模式相关的资料有很多,概念性的东西就画个图就可以了.把关注点放在例子上,设计模式还是要使用中才有感受. 从Factory Method&Abstract Factor ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- java设计模式大全 Design pattern samples in Java(最经典最全的资料)
java设计模式大全 Design pattern samples in Java(最经典最全的资料) 2015年06月19日 13:10:58 阅读数:11100 Design pattern sa ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
- Scalaz(10)- Monad:就是一种函数式编程模式-a design pattern
Monad typeclass不是一种类型,而是一种程序设计模式(design pattern),是泛函编程中最重要的编程概念,因而很多行内人把FP又称为Monadic Programming.这其中 ...
随机推荐
- 51nod1934:受限制的排列 (分治+组合数)
对于一个 11 到 nn 的排列 p1,p2,⋯,pnp1,p2,⋯,pn ,我们可以轻松地对于任意的 1≤i≤n1≤i≤n 计算出 (li,ri)(li,ri) ,使得对于任意的 1≤L ...
- POJ1226(strstr)
Substrings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13348 Accepted: 4722 Descr ...
- c++ _宏与内联函数
第一部分:宏为什么要使用宏呢?因为函数的调用必须要将程序执行的顺序转移到函数所存放在内存中的某个地址,将函数的程序内容执行完后,再返回到转去执行该函数前的地方.这种转移操作要求在转去执行前要保存现场并 ...
- Understand中的Graphical Views使用
Graphical Views 用于浏览代码结构. 下面以dso为例 1.Butterfly 显示include关系.例: 2.Declaration 文件中的类.例: 3.UML Class Dia ...
- android调试之adb
ADB 其实大部分的PC开发机与Android设备的操作都是通过adb(android debug bridge)技术完成的,这是一个C/S架构的命令行工具,主要由三个部分组成 运行在PC开发机上的命 ...
- jQuery EasyUI API 中文文档 - Tree树使用介绍
用 $.fn.tree.defaults 重写了 defaults. 依赖 draggable droppable 用法 Tree 能在 <ul> 元素里定义,此标记可以定义为叶节点和子节 ...
- 大将军UE分析
1.过关奖励,先播放特效,在显示奖励 2.鼠标移到人物身上装备,提示双击卸载 3.战场随机事件,出发开启增加buff 4.主线任务简单化,副本支线可玩性增强 5.乌泱泱几十个活动 6.升级的爽快感[升 ...
- C#基础:使用Thread创建线程
Thread类可以创建和控制线程,Thread类的构造函数重载为接受ThreadStart和ParameterizedThreadStart类型的委托参数.下面我们用一个例子来解释怎样用Thread类 ...
- 洛谷 - P2158 - 仪仗队 - 欧拉函数
https://www.luogu.org/problemnew/show/P2158 好像以前有个妹子收割铲也是欧拉函数. 因为格点直线上的点,dx与dy的gcd相同,画个图就觉得是欧拉函数.但是要 ...
- hihocoder #1608 : Jerry的奶酪(状压DP)
传送门 题意 分析 设dp[i][j]为在i状态下当前在第j个奶酪的最小费用 转移方程:dp[(1<<k)|i][k]=dp[i][j]+d[j][k] 预处理出每个奶酪之间的距离,加入起 ...