青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++研究

C++細節深度探索及軟件工程

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  37 隨筆 :: 0 文章 :: 74 評論 :: 0 Trackbacks
The Gof has 23 design patterns , but in most of  the design books , the E.G is written in Java , So  from now on , I will write about 23 articles to implement them using C++ , the design pattern itself is discussible , so welcome everyone to give his excelent idea to me , My QQ: 286259397 And My MSN : cxl82116@msn.com.
Welcome every one to express his ideas!

 


This is the Second Arcticle: ADAPTER PATTERN

While
referring to Adapter pattern , there must be a class that play the role of a adapter which can make two or more umcompatible class compatible . To explain this world , the UML diagram can make it clear easily :


        diagram 2-1 Class Adapter UML (referred from http://terrylee.cnblogs.com)


        diagram 2-2  Object Adapter UML (referred from http://terrylee.cnblogs.com)


E.G Explain them sparetely:
if a Customer request a  CUP WITH A CAP , but the orgin system can only supply a CUP , So you it's not compatible between the Request and the Orgin System , so you must find anthor factory who supply the cap ,and make it together to statisfy the customer ,  implement it in Class Adapter Pattern , Codes goes below.
Class Adapter Pattern:

 1/********************************************************************
 2    created:    2007/04/21
 3    created:    21:4:2007   18:47
 4    filename:     c:\Visual Studio 2005\Projects\Frist2005\Frist2005\Frist2005.cpp
 5    file path:    c:\Visual Studio 2005\Projects\Frist2005\Frist2005
 6    file base:    Frist2005
 7    file ext:    cpp
 8    author:        Chang Xinglong(King.C)
 9    
10    purpose:    Adapter Pattern -Class
11*********************************************************************/

12
13#include "stdafx.h"
14#include <map>
15#include <iostream>
16
17using namespace std;
18
19class OrginSystem
20{
21
22public:
23    void Supply()
24    {
25        cout<<"Orgin:SupplyACup"<<endl;
26    }

27}
;
28class CapSystem
29{
30public:
31    void Supply()
32    {
33        cout<<"CapSystem:SupplyACap"<<endl;
34    }

35}
;
36class Adapter: public OrginSystem , CapSystem
37{
38public:
39    void Supply()
40    {
41        OrginSystem::Supply();
42        CapSystem::Supply();
43        cout<<"So the request has been satisfied!"<<endl;
44    }

45}
;
46int _tmain(int argc, _TCHAR* argv[])
47{
48    Adapter _adpter;
49    _adpter.Supply();
50    system("pause");
51    return 0;
52}

The Same question , implement it using Object Adapter Pattern:
 1/********************************************************************
 2    created:    2007/04/21
 3    created:    21:4:2007   18:47
 4    filename:     c:\Visual Studio 2005\Projects\Frist2005\Frist2005\Frist2005.cpp
 5    file path:    c:\Visual Studio 2005\Projects\Frist2005\Frist2005
 6    file base:    Frist2005
 7    file ext:    cpp
 8    author:        Chang Xinglong(King.C)
 9    
10    purpose:    Adapter Pattern-Object 
11*********************************************************************/

12
13#include "stdafx.h"
14#include <map>
15#include <iostream>
16
17using namespace std;
18
19class OrginSystem
20{
21
22public:
23    void Supply()
24    {
25        cout<<"Orgin:SupplyACup"<<endl;
26    }

27}
;
28class CapSystem
29{
30public:
31    void Supply()
32    {
33        cout<<"CapSystem:SupplyACap"<<endl;
34    }

35}
;
36class Adapter: public OrginSystem , CapSystem
37{
38public:
39    Adapter():_os(new OrginSystem),_cs(new CapSystem)
40    {
41
42    }

43    void Supply()
44    {
45        _os->Supply();
46        _cs->Supply();
47        cout<<"So the request has been satisfied!"<<endl;
48    }

49private:
50    OrginSystem *_os;
51    CapSystem * _cs;
52}
;
53int _tmain(int argc, _TCHAR* argv[])
54{
55    OrginSystem _orign=new _adpter();
56    _orign.Supply();
57    system("pause");
58    return 0;
59}

60
61

In C++ , Muiltple-Derived pattern is not a recommend pattern, So if possible , use the Obeject -Adpter Pattern.

That's all ,Thanks! if any different idea , send me E-mail.
posted on 2007-04-21 19:13 常興龍 閱讀(1472) 評論(4)  編輯 收藏 引用 所屬分類: Design Patterns & Engeering

評論

# re: Implement "GOF's Adapter pattern" Using C++(Series of Gof patterns using C++ 2nd article) 2007-04-22 13:23 kurt
I think the UML is enough for us to understand it  回復  更多評論
  

# re: Implement "GOF's Adapter pattern" Using C++(Series of Gof patterns using C++ 2nd article) 2007-04-22 14:47 天津大學計算機學院 常興龍
hehe ,thanks for your comment , it's just for the beginner study c++ systemly and this article can demostrate that how to implement interface( in Java , there is the Keyword interface) using virtual function in C++ , the uml itself didn't express this. Thanks again!  回復  更多評論
  

# re: Implement "GOF's Adapter pattern" Using C++(Series of Gof patterns using C++ 2nd article) 2007-04-22 21:27 ★田德健★
all are english....  回復  更多評論
  

# re: Implement "GOF's Adapter pattern" Using C++(Series of Gof patterns using C++ 2nd article) 2007-09-12 15:47 Andrew Selivanov
I suppose this would be more compatible version (see below)
----------------------------------------------------------
#include <iostream>

#define USE_ADAPTER
#ifndef USE_ADAPTER

class OrginSystem
{

public:
void Supply()
{
std::cout<<"Orgin:SupplyACup"<<std::endl;
}
};
class CapSystem
{
public:
void Supply()
{
std::cout<<"CapSystem:SupplyACap"<<std::endl;
}
};
class Adapter: public OrginSystem , CapSystem
{
public:
void Supply()
{
OrginSystem::Supply();
CapSystem::Supply();
std::cout<<"So the request has been satisfied!"<<std::endl;
}
};

int main()
{
Adapter adapter;
adapter.Supply();
}
#else

class OrginalSystem
{

public:

virtual void Supply()
{
std::cout<<"Orgin:SupplyACup"<<std::endl;
}
};
class CapSystem
{
public:
virtual void Supply()
{
std::cout<<"CapSystem:SupplyACap"<<std::endl;
}
};
class Adapter: public OrginalSystem , CapSystem
{
OrginalSystem* _os;
CapSystem* _cs;

public:
Adapter():_os(new OrginalSystem),_cs(new CapSystem)
{

}
void Supply()
{
_os->Supply();
_cs->Supply();
std::cout<<"So the request has been satisfied!"<<std::endl;
}
};

int main()
{
OrginalSystem* original = new Adapter();
original->Supply();
delete original;
}

#endif
----------------------------------------------------------
Andrew  回復  更多評論
  

> hi的博客
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美一级免费视频| 久久精品国产91精品亚洲| 欧美福利在线| 亚洲精品视频在线观看免费| 噜噜噜躁狠狠躁狠狠精品视频| 国外成人在线视频| 久久嫩草精品久久久精品| 欧美综合国产精品久久丁香| 狠狠狠色丁香婷婷综合激情| 免费日韩一区二区| 欧美成人免费全部| 亚洲深夜av| 亚洲在线黄色| 在线观看久久av| 亚洲激情午夜| 国产精品分类| 久久精品国产免费| 男人的天堂亚洲| 中日韩男男gay无套| 亚洲免费小视频| 另类欧美日韩国产在线| 久久这里有精品视频| 亚洲高清一区二区三区| 日韩视频永久免费观看| 国产日本亚洲高清| 亚洲高清视频在线| 国产精品高潮呻吟久久av无限 | 亚洲韩国青草视频| 欧美大片免费久久精品三p| 亚洲素人一区二区| 欧美一区观看| 一区二区精品在线观看| 欧美一区二区日韩一区二区| 亚洲区第一页| 久久爱www久久做| 日韩亚洲视频在线| 欧美专区在线播放| 99这里有精品| 久久免费视频在线观看| 国产精品99久久久久久久女警| 久久夜色精品国产亚洲aⅴ| 免费不卡欧美自拍视频| 欧美亚洲一区二区在线| 欧美成人免费在线| 久久这里只精品最新地址| 欧美日韩中文另类| 欧美黄网免费在线观看| 国产欧美日韩另类视频免费观看| 亚洲淫性视频| 欧美精品123区| 久久精品一区二区三区不卡牛牛| 日韩小视频在线观看| 亚洲欧美日韩一区二区三区在线| 国产精品任我爽爆在线播放| 亚洲美女在线视频| 久久成人一区| 一区在线视频| 免费人成精品欧美精品| 亚洲精品视频在线观看免费| 久久久噜噜噜久久中文字幕色伊伊 | 亚洲免费福利视频| 国产一区二区精品久久| 亚洲精品久久久久久下一站| 日韩写真在线| 欧美精品一区二区三区四区| 美女91精品| 中文精品视频一区二区在线观看| 在线视频欧美日韩精品| 久久嫩草精品久久久精品| 欧美色区777第一页| 夜夜嗨av一区二区三区中文字幕| 欧美黄色视屏| 久久综合电影| 亚洲乱码日产精品bd| 久久精品一区二区三区不卡牛牛 | 你懂的成人av| 欧美在线观看网址综合| 国产精品久久久久久五月尺| 亚洲免费观看高清完整版在线观看| 欧美日韩a区| 亚洲精选久久| 宅男66日本亚洲欧美视频| 欧美日韩精品国产| 99国产精品国产精品久久| 一区二区三区国产在线观看| 欧美日韩性生活视频| 亚洲视频免费在线| 久久久久免费视频| 亚洲高清不卡在线观看| 欧美激情一区在线观看| 99精品热6080yy久久 | 久久精品亚洲精品国产欧美kt∨| 精品99视频| 欧美成人高清| 日韩视频在线观看免费| 亚洲免费小视频| 国产一区二区三区四区hd| 久久综合中文色婷婷| 亚洲美女区一区| 欧美一区亚洲一区| 亚洲国产日韩欧美综合久久| 欧美噜噜久久久xxx| 午夜精品一区二区三区电影天堂| 日韩亚洲在线| 国产欧美精品xxxx另类| 久久一区精品| 在线亚洲国产精品网站| 美女日韩在线中文字幕| 日韩亚洲成人av在线| 欧美日本国产| 久久精品91| 亚洲日本中文字幕免费在线不卡| 伊大人香蕉综合8在线视| 欧美精品久久一区| 久久精彩免费视频| 99视频精品免费观看| 久热精品视频在线观看| 99re热这里只有精品视频| 国产欧美一区二区精品性 | 久久国产直播| 99精品免费| 在线观看欧美视频| 国产精品毛片a∨一区二区三区| 欧美成人免费网| 欧美在线观看一区| 一级成人国产| 亚洲高清久久| 国产专区一区| 国产精品网红福利| 欧美精品三级日韩久久| 久久久噜噜噜久久| 亚洲宅男天堂在线观看无病毒| 一区二区三区国产在线观看| 一区二区三区在线观看国产| 欧美日韩国产三级| 欧美成人精品h版在线观看| 国产偷久久久精品专区| 欧美伦理a级免费电影| 久久午夜激情| 久久久久久9| 午夜一区二区三区不卡视频| 亚洲精品日产精品乱码不卡| 免费亚洲一区二区| 麻豆成人在线观看| 久久免费国产| 久久婷婷麻豆| 久久久久久一区二区三区| 久久精品国产久精国产思思| 久久成人免费| 久久九九精品| 久久中文在线| 欧美国产专区| 久久久久免费观看| 免费的成人av| 亚洲国产天堂网精品网站| 欧美激情按摩| 亚洲黄色免费电影| 亚洲日本欧美| 日韩一级在线观看| 亚洲先锋成人| 久久国产精品久久精品国产| 亚洲欧美国产高清va在线播| 老牛国产精品一区的观看方式| 欧美人与性动交a欧美精品| 久久久国产一区二区| 欧美日韩高清在线一区| 久久视频这里只有精品| 国产一区二区0| 亚洲午夜视频| 久久精品青青大伊人av| 国产精品福利在线| 欧美国产高清| 亚洲国产天堂久久综合| 欧美一级专区免费大片| 亚洲视频一起| 亚洲精品老司机| 亚洲男同1069视频| 免费观看成人鲁鲁鲁鲁鲁视频| 日韩一区二区精品| 久久精品91| 日韩亚洲国产欧美| 午夜精品久久久久久久久久久久| 国内揄拍国内精品少妇国语| 在线看无码的免费网站| 一区二区成人精品| 久久久久久69| 99成人在线| 蜜桃av一区二区在线观看| 欧美日韩一区综合| 亚洲电影第1页| 亚洲自拍偷拍麻豆| 欧美a级片网| 亚洲性人人天天夜夜摸| 猛男gaygay欧美视频| 国产精品日韩一区| 99精品国产高清一区二区| 欧美一区二区日韩| 亚洲精选91| 免费在线欧美黄色| 国产视频丨精品|在线观看|