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

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>
            亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 亚洲精品国产品国语在线app| 欧美在线不卡| 欧美一区2区三区4区公司二百| 国产欧美综合在线| 久久久精品午夜少妇| 久久久久9999亚洲精品| 亚洲国产精品一区二区第四页av| 免费看成人av| 欧美精品在线免费播放| 中日韩美女免费视频网址在线观看 | 欧美电影免费观看大全| 美国十次成人| 亚洲伊人一本大道中文字幕| 亚洲永久免费视频| 狠狠久久综合婷婷不卡| 亚洲第一二三四五区| 欧美精品日韩精品| 午夜精品久久久| 久久国产主播| 亚洲视频福利| 久久国产精品久久久久久久久久 | 亚洲一级电影| 国产精品亚发布| 欧美福利电影网| 欧美日韩一级黄| 久久中文字幕一区| 欧美日韩在线精品| 亚洲天堂成人在线观看| 小黄鸭精品密入口导航| 亚洲国产日韩欧美在线动漫| 亚洲精品一品区二品区三品区| 国产麻豆日韩| 亚洲日本黄色| 永久91嫩草亚洲精品人人| 99视频国产精品免费观看| 经典三级久久| 亚洲在线观看视频| 99国产欧美久久久精品| 久久激情视频| 欧美一区不卡| 欧美日韩一区二区在线观看视频| 久久久中精品2020中文| 欧美手机在线| 亚洲国产综合视频在线观看| 国产一区二区在线免费观看| 一区二区三区欧美在线观看| 91久久精品一区| 久久久久久久波多野高潮日日| 性久久久久久久久| 欧美日韩一区在线| 亚洲人成在线观看一区二区| 亚洲国产精品女人久久久| 欧美一区二区精品在线| 午夜日韩激情| 国产精品久久久久久久久久久久久久 | 亚洲尤物在线视频观看| 欧美激情中文字幕乱码免费| 美日韩精品视频免费看| 国产又爽又黄的激情精品视频| 一二三四社区欧美黄| 99精品欧美| 欧美日韩第一区日日骚| 亚洲国产欧美在线人成| 亚洲国产日韩一区| 免费成人美女女| 亚洲第一天堂av| 亚洲黄一区二区| 欧美电影免费观看高清| 欧美激情在线播放| 亚洲伦理在线观看| 欧美连裤袜在线视频| 亚洲激情一区二区| 99精品免费视频| 欧美视频在线免费看| 中文久久精品| 久久精品国产欧美激情| 国产在线视频欧美一区二区三区| 欧美在线一二三四区| 另类激情亚洲| 亚洲老板91色精品久久| 欧美激情视频在线播放| 亚洲免费大片| 性视频1819p久久| 国内揄拍国内精品少妇国语| 久久综合激情| 亚洲另类一区二区| 性色av一区二区三区| 国产一区二区久久久| 毛片一区二区三区| a4yy欧美一区二区三区| 久久精品一本| 亚洲肉体裸体xxxx137| 欧美视频一区二区| 久久精品一区二区三区不卡牛牛| 亚洲第一中文字幕在线观看| 亚洲一区二区三区777| 国产亚洲欧美一区| 欧美激情亚洲自拍| 午夜在线精品| 亚洲福利小视频| 香蕉久久夜色| 亚洲精品国产精品国自产观看| 国产精品成人观看视频免费| 久久久久久久999| 日韩一区二区精品葵司在线| 久久成人精品视频| 夜夜躁日日躁狠狠久久88av| 国产真实乱偷精品视频免| 欧美激情五月| 久久久欧美精品sm网站| 一区二区三区四区五区在线| 牛牛影视久久网| 欧美中文字幕第一页| 99精品久久久| 激情亚洲成人| 国产精品亚洲а∨天堂免在线| 欧美成人资源网| 欧美在线免费观看| 在线中文字幕一区| 亚洲国产一二三| 久久综合导航| 久久精品女人的天堂av| 亚洲免费在线精品一区| 亚洲每日更新| 91久久在线视频| 红桃av永久久久| 国产亚洲精品v| 国产精品私人影院| 欧美性jizz18性欧美| 欧美日本亚洲| 欧美精品七区| 欧美日韩成人网| 欧美精品导航| 欧美另类变人与禽xxxxx| 久久综合综合久久综合| 久久午夜精品一区二区| 欧美在线观看网址综合| 亚洲欧美色一区| 午夜精品亚洲| 欧美一区二区三区免费视频| 亚洲欧美在线免费观看| 午夜精品免费| 欧美一区2区三区4区公司二百 | 麻豆久久婷婷| 另类图片综合电影| 免费在线视频一区| 欧美1区3d| 亚洲高清自拍| 亚洲日本成人女熟在线观看| 亚洲激情午夜| 一区二区三区高清不卡| 日韩视频一区二区三区| 这里只有精品丝袜| 亚洲综合日本| 久久精品国产2020观看福利| 久久久久成人网| 欧美va亚洲va日韩∨a综合色| 美女亚洲精品| 欧美日韩少妇| 国产网站欧美日韩免费精品在线观看 | 亚洲特级毛片| 欧美亚洲专区| 麻豆国产精品va在线观看不卡| 免费在线视频一区| 欧美日韩在线视频一区| 国产裸体写真av一区二区| 国产婷婷一区二区| 亚洲精品一区二区三区不| 在线视频你懂得一区二区三区| 亚洲欧美日韩国产综合在线| 久久精品国产欧美激情| 欧美激情精品久久久六区热门 | 亚洲黄色尤物视频| 一本色道久久综合一区| 性久久久久久| 女女同性精品视频| 国产精品久久久久久亚洲毛片| 国产一区二区三区免费在线观看 | 欧美新色视频| 国内精品嫩模av私拍在线观看| 亚洲人成久久| 久久国产天堂福利天堂| 亚洲福利专区| 午夜伦理片一区| 欧美精品久久久久久久久久| 国产精品蜜臀在线观看| 亚洲激情电影中文字幕| 香蕉国产精品偷在线观看不卡| 女同一区二区| 午夜精品av| 欧美日韩国产一区| 激情欧美亚洲| 性欧美暴力猛交另类hd| 亚洲国产成人精品视频| 午夜视频久久久| 欧美午夜激情在线| 亚洲精品欧洲| 免费视频最近日韩| 先锋影音久久|