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

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 常興龍 閱讀(1462) 評論(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>
            亚洲欧美一区二区视频| 亚洲国语精品自产拍在线观看| 日韩亚洲视频在线| 亚洲高清一二三区| 久久视频在线看| 日韩手机在线导航| 一区二区三区日韩精品视频| 亚洲国产乱码最新视频| 国产区精品视频| 欧美在线欧美在线| 久久婷婷久久一区二区三区| 亚洲欧洲日韩综合二区| 99国产麻豆精品| 国产伦精品一区二区三区照片91 | 亚洲电影网站| 亚洲精品美女久久久久| 国产精品久久久久久久久久妞妞| 久久国产视频网站| 欧美~级网站不卡| 亚洲一区二区高清视频| 久久精品99国产精品日本| 亚洲国产mv| 亚洲少妇自拍| 亚洲国产婷婷综合在线精品 | 亚洲日本无吗高清不卡| 国产精品综合不卡av| 久久在线精品| 欧美三区在线| 免费一区二区三区| 国产精品久久久久久久久免费樱桃 | 久久国产主播| 妖精成人www高清在线观看| 亚洲欧美国产77777| 亚洲精品一区二区三区蜜桃久| 久久综合色综合88| 亚洲高清视频的网址| 亚洲午夜视频| 一区二区三区国产在线观看| 久久久国产一区二区| 亚洲无限乱码一二三四麻| 久久久一区二区| 久久国产主播| 国产精品久久久久久久第一福利| 欧美黑人国产人伦爽爽爽| 国产欧美一级| 在线视频精品一区| 日韩午夜电影在线观看| 久久另类ts人妖一区二区| 欧美诱惑福利视频| 国产精品video| 日韩午夜中文字幕| 99热这里只有精品8| 免费中文日韩| 欧美福利电影在线观看| 狠狠色狠色综合曰曰| 午夜在线一区二区| 欧美一级二级三级蜜桃| 国产精品久久午夜夜伦鲁鲁| 亚洲经典视频在线观看| 亚洲国产欧美日韩另类综合| 久久久久一区| 另类综合日韩欧美亚洲| 国产一区二区你懂的| 午夜精品久久| 久久久久久久高潮| 国产亚洲午夜| 欧美在线视频导航| 久久久噜噜噜久久中文字幕色伊伊 | 亚洲精品综合精品自拍| 亚洲美女在线一区| 欧美国产日韩视频| 亚洲激情午夜| 中国成人黄色视屏| 国产精品福利片| 亚洲综合色激情五月| 欧美激情视频网站| 国内不卡一区二区三区| 久久久夜精品| 亚洲国产精品传媒在线观看| 日韩午夜中文字幕| 国产精品国产| 香蕉国产精品偷在线观看不卡 | 亚洲激情电影在线| 欧美日韩国内自拍| 亚洲综合色噜噜狠狠| 久久综合激情| 99亚洲视频| 国产精品日韩久久久久| 久久av资源网站| 亚洲黄色免费| 性欧美大战久久久久久久免费观看| 国产亚洲电影| 欧美激情麻豆| 午夜精品久久久久影视| 日韩一级裸体免费视频| 国产精品久久久久av免费| 亚洲欧美日韩一区二区三区在线观看| 久久久天天操| 在线视频精品一| 国产一区二区三区久久| 欧美国产国产综合| 亚洲在线黄色| 亚洲国产精品久久久久| 亚洲专区一区| 91久久精品久久国产性色也91| 欧美日韩精品一区二区| 欧美综合二区| 亚洲毛片av| 美日韩精品视频| 亚洲综合视频1区| 亚洲三级视频| 国内成+人亚洲| 国产精品乱子久久久久| 欧美+日本+国产+在线a∨观看| 亚洲一区二区在线免费观看| 亚洲激情在线观看| 久久综合九九| 欧美在线看片a免费观看| 一本一本久久a久久精品牛牛影视| 国产视频在线观看一区二区| 亚洲破处大片| 久久精品人人做人人爽电影蜜月| 亚洲国产精品美女| 狼人天天伊人久久| 午夜亚洲伦理| 亚洲欧美激情视频在线观看一区二区三区| 亚洲成色www久久网站| 国产欧美一区二区三区视频| 国产精品久久7| 欧美日韩国产不卡| 免费亚洲一区二区| 美女爽到呻吟久久久久| 久久成人免费日本黄色| 欧美一区二区大片| 午夜精品偷拍| 亚洲欧美日韩精品久久奇米色影视| av不卡在线观看| av成人免费| 一本久久a久久免费精品不卡| 亚洲国产91精品在线观看| 欧美chengren| 久久亚洲电影| 欧美成年人网| 亚洲国产一区二区精品专区| 欧美国产一区二区| 亚洲国产精品嫩草影院| 亚洲国产老妈| 亚洲人成网站在线播| 亚洲国产精品电影在线观看| 亚洲国内欧美| 一本一本久久a久久精品综合妖精| 99视频热这里只有精品免费| 宅男噜噜噜66一区二区66| 亚洲一区二区黄色| 午夜老司机精品| 久久久久久亚洲精品杨幂换脸 | 亚洲影院一区| 久久国产天堂福利天堂| 久久久久一区二区| 欧美精品性视频| 国产精品久久国产精麻豆99网站| 国产精自产拍久久久久久| 黄色小说综合网站| 亚洲经典三级| 亚洲主播在线播放| 久久久精品国产免大香伊| 久久午夜精品| 91久久精品一区| 亚洲欧美日本伦理| 噜噜噜噜噜久久久久久91| 欧美成人精品在线播放| 国产精品女主播一区二区三区| 久久久久综合一区二区三区| 亚洲激情欧美激情| 亚洲一区二区精品| 久久亚洲精品中文字幕冲田杏梨| 欧美国产亚洲另类动漫| 国产精品天天摸av网| 亚洲国产女人aaa毛片在线| 一区二区三区久久网| 久久躁狠狠躁夜夜爽| 日韩视频一区二区三区| 久久精品免费| 国产精品久久久久久久一区探花| 国语自产精品视频在线看| 一区二区三区视频免费在线观看| 欧美在线看片a免费观看| 亚洲国产精品t66y| 午夜精品久久久久久99热| 欧美精品在线一区| 激情成人综合| 午夜精品国产更新| 最新日韩在线视频| 久久精品中文字幕一区二区三区 | 亚洲少妇一区| 欧美高清免费| 在线看片成人| 久久av一区二区三区| 99精品欧美一区二区三区综合在线| 久久久久久高潮国产精品视|