:适配器模式: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 ...
随机推荐
- Axure 第一个原型 简单的登录页面
设置所有元件的尺寸和位置的时候都是借助截图软件来调整位置的
- ThinkPHP的数据操作
查询: 具体数据的操作方法使用: 1. where()条件 $model->where(条件值); //条件值就是sql语句where后边的结果值 2. limit() 限制条数 $ ...
- Aliyun cdn访问日志下载
1.日志下载代码(cdn.py)(请在Linux系统下运行) #!/usr/bin/python2.7 # -*- coding:utf-8 -*- import sys,os,gzip,json,r ...
- LeetCode--458--可怜的小猪
问题描述: 有1000只水桶,其中有且只有一桶装的含有毒药,其余装的都是水.它们从外观看起来都一样.如果小猪喝了毒药,它会在15分钟内死去. 问题来了,如果需要你在一小时内,弄清楚哪只水桶含有毒药,你 ...
- 2 爬虫 requests模块
requests模块 Requests是用python语言基于urllib编写的,采用的是Apache2 Licensed开源协议的HTTP库,Requests它会比urllib更加方便,reques ...
- 【洛谷p1012】拼数
(今天yuezhuren大课间放我们出来了……) (另外今天回了两趟初中部) 拼数[传送门] 洛谷算法标签: (然鹅这两个学的都不好,能过真的how strange) 开始的时候没读题啊,直接暴力so ...
- 基于散列的集合 HashSet\HashMap\HashTable
HashSet\HashMap\HashTable 1 基于散列的集合 2 元素会根据hashcode散列,因此,集合中元素的顺序不一定与插入的顺序一致. 3 根据equals方法与hashCode方 ...
- pytorch初步学习(一):数据读取
最近从tensorflow转向pytorch,感受到了动态调试的方便,也感受到了一些地方的不同. 所有实验都是基于uint16类型的单通道灰度图片. 一开始尝试用opencv中的cv.imread读取 ...
- leetcode-algorithms-30 Substring with Concatenation of All Words
leetcode-algorithms-30 Substring with Concatenation of All Words You are given a string, s, and a li ...
- leetcode-algorithms-23 Merge k Sorted Lists
leetcode-algorithms-23 Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted ...