:适配器模式:Adapter
#ifndef __ADAPTER_H__
#define __ADAPTER_H__
#include <iostream>
using namespace std;
class Duck
{
public:
Duck(){}
virtual ~Duck(){}
virtual void Quack()
{
cout << "Duck Quack" << endl;
}
virtual void Fly()
{
cout << "Duck Fly" << endl;
}
}; class MallardDuck : public Duck
{
public:
MallardDuck(){}
virtual ~MallardDuck(){}
virtual void Quack()
{
cout << "MallardDuck Quack" << endl;
}
virtual void Fly()
{
cout << "MallardDuck Fly" << endl;
}
}; class Turkey
{
public:
Turkey(){}
virtual ~Turkey(){}
virtual void Gobble()
{
cout << "Turkey Gobble" << endl;
}
virtual void Fly()
{
cout << "Turkey Fly" << endl;
}
}; class WildTurkey : public Turkey
{
public:
WildTurkey(){}
virtual ~WildTurkey(){}
virtual void Gobble()
{
cout << "WildTurkey Gobble" << endl;
}
virtual void Fly()
{
cout << "WildTurkey Fly" << endl;
}
}; class TuikeyAdapter : public Duck
{
private:
Turkey * turkey;
public:
TuikeyAdapter(Turkey *t)
{
turkey = t;
}
virtual~TuikeyAdapter(){}
virtual void Quack()
{
turkey->Gobble();
}
virtual void Fly()
{
for (int i = 0; i < 3; i++)
{
turkey->Fly();
}
}
}; class AdapterClass :public virtual Duck, public virtual Turkey
{ }; #endif
#include <iostream>
#include "Adapter.h"
using namespace std;
int main()
{
Turkey *wtk = new WildTurkey();
Duck *d = new TuikeyAdapter(wtk);
d->Quack();
d->Fly(); Duck *a = new AdapterClass();
a->Quack(); return 0;
}
:适配器模式:Adapter的更多相关文章
- 二十四种设计模式:适配器模式(Adapter Pattern)
适配器模式(Adapter Pattern) 介绍将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作.示例有一个Message实体类 ...
- 设计模式 - 适配器模式(adapter pattern) 具体解释
适配器模式(adapter pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 适配器模式(adapter pattern): 将一个类的接 ...
- 设计模式(五)适配器模式Adapter(结构型)
设计模式(五)适配器模式Adapter(结构型) 1. 概述: 接口的改变,是一个需要程序员们必须(虽然很不情愿)接受和处理的普遍问题.程序提供者们修改他们的代码;系统库被修正;各种程序语言以及相 ...
- 设计模式(三)-- 适配器模式(Adapter)
适配器模式(Adapter) 考虑一个记录日志的应用,由于用户对日志记录的要求很高,使得开发人员不能简单地采用一些已有的日志工具或日志框架来满足用户的要求,而需要按照用户的要求重新开发新的日志管理系统 ...
- 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
原文:乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) 作者:webabc ...
- 【设计模式】适配器模式 Adapter Pattern
适配器模式在软件开发界使用及其广泛,在工业界,现实中也是屡见不鲜.比如手机充电器,笔记本充电器,广播接收器,电视接收器等等.都是适配器. 适配器主要作用是让本来不兼容的两个事物兼容和谐的一起工作.比如 ...
- 适配器模式-Adapter(Java实现)
适配器模式-Adapter 是作为两个不兼容的接口之间的桥梁. 本篇文章的代码github地址: https://github.com/GoldArowana/design-patterns/tree ...
- 8.3 GOF设计模式二: 适配器模式 Adapter
GOF设计模式二: 适配器模式 Adapter 为中国市场生产的电器,到了美国,需要有一个转接器才能使用墙上的插座,这个转接 器的功能.原理?复习单实例模式 SingleTon的三个关键点 ...
- 怎样让孩子爱上设计模式 —— 7.适配器模式(Adapter Pattern)
怎样让孩子爱上设计模式 -- 7.适配器模式(Adapter Pattern) 标签: 设计模式初涉 概念相关 定义: 适配器模式把一个类的接口变换成client所期待的还有一种接口,从而 使原本因接 ...
- 设计模式 - 适配器模式(adapter pattern) 枚举器和迭代器 具体解释
适配器模式(adapter pattern) 枚举器和迭代器 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考适配器模式(adapter patter ...
随机推荐
- (转)C# Assembly.Load 使用
在C#中,我们要使用反射,首先要搞清楚以下命名空间中几个类的关系: System.Reflection命名空间(1) AppDomain:应用程序域,可以将其理解为一组程序集的逻辑容器(2) As ...
- [Win10]安装msi时2503,2502错误及其解决
简述 刚安装了win10系统,在安装TortoiseGit和TortoiseSvn时,这两个软件是.msi后缀的安装文件,在点击安装时老是提示2503,2502错误,因此无法安装上 搜索了下一般都提到 ...
- (转) gffcompare和gffread | gtf | gff3 格式文件的分析 | gtf处理 | gtfparse
工具推荐:https://github.com/openvax/gtfparse 真不敢相信,Linux自带的命令会这么强大,从gtf中提取出需要的transcript,看起来复杂,其实一个grep就 ...
- 创建型模式之Builder(建造者)模式
GitHub地址:https://github.com/zhangboqing/design-mode/tree/master/src/main/java/com/zbq 一.定义 建造者模式 ...
- 20190118_xlVBA多表合并
Public Sub simple() Set wb = ActiveWorkbook Set sht = ActiveSheet msg = MsgBox("程序准备清除活动工作表内容?按 ...
- anaconda安装tensorflow
1.下载anaconda python3.5版本,Windows不支持python3.6,linux和mac支持python2.7和python3.3+ 2.创建环境 conda create - ...
- MySQL的自动补全和语法高亮工具MyCli
官方地址: RHEL, Centos: We don't have packages for RHEL or Centos, yet. Instead, use pip to install mycl ...
- array_unique
array_unique() 函数移除数组中的重复的值,并返回结果数组. 当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除. 返回的数组中键名不变. <?php $a=array(& ...
- 『计算机视觉』Mask-RCNN_推断网络其一:总览
在我们学习的这个项目中,模型主要分为两种状态,即进行推断用的inference模式和进行训练用的training模式.所谓推断模式就是已经训练好的的模型,我们传入一张图片,网络将其分析结果计算出来的模 ...
- 纯css实现顶部进度条随滚动条滚动
<!DOCTYPE html> <head> <meta charset="utf-8"> <meta http-equiv=" ...