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

C++研究

C++細(xì)節(jié)深度探索及軟件工程

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  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 常興龍 閱讀(1459) 評論(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  回復(fù)  更多評論
  

# re: Implement "GOF's Adapter pattern" Using C++(Series of Gof patterns using C++ 2nd article) 2007-04-22 14:47 天津大學(xué)計(jì)算機(jī)學(xué)院 常興龍
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!  回復(fù)  更多評論
  

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

# 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  回復(fù)  更多評論
  

> 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精品| 久久成人免费电影| 亚洲国产成人不卡| 免费亚洲一区| 一区二区三区www| aa级大片欧美三级| 国产伦精品一区二区三区免费迷 | 99在线热播精品免费| 亚洲人成网站在线播| 欧美三级免费| 久久国产精品久久久久久久久久| 久久成人这里只有精品| 亚洲精品乱码久久久久久蜜桃麻豆 | 国产日韩一区二区三区在线播放| 久久精品国产一区二区电影| 老色鬼精品视频在线观看播放| 91久久精品日日躁夜夜躁欧美| 日韩一级大片在线| 国产一区香蕉久久| 亚洲靠逼com| 狠狠入ady亚洲精品| 亚洲区第一页| 国产日韩欧美黄色| 亚洲精品国产品国语在线app| 国产精品一区二区你懂得| 久久综合色播五月| 欧美午夜宅男影院| 亚洲盗摄视频| 国产午夜精品视频| 亚洲人成网站精品片在线观看| 国产日韩精品一区观看| 亚洲精品免费在线观看| 好看不卡的中文字幕| 中日韩男男gay无套| 亚洲级视频在线观看免费1级| 午夜久久资源| 在线午夜精品自拍| 欧美成人免费观看| 久久亚洲视频| 国产精品自在在线| 99在线视频精品| 亚洲丰满在线| 久久精品在线| 久久高清免费观看| 国产精品视频yy9099| 亚洲精品乱码久久久久久| 精品1区2区3区4区| 欧美一区二区三区免费视| 亚洲视频图片小说| 欧美精品激情| 亚洲国产精品高清久久久| 韩国欧美一区| 久久精品人人爽| 久久综合狠狠| 国内视频一区| 久久久噜噜噜久久中文字免| 久久爱www| 国产性天天综合网| 性欧美18~19sex高清播放| 午夜精品久久久| 国产精品国产成人国产三级| 99在线热播精品免费99热| aa日韩免费精品视频一| 欧美女同在线视频| 亚洲精品一级| 亚洲在线第一页| 国产精品美女主播| 亚洲欧美电影在线观看| 校园激情久久| 国产亚洲欧美日韩在线一区 | 亚洲国产裸拍裸体视频在线观看乱了中文 | 国产精品免费久久久久久| aa成人免费视频| 午夜精品一区二区三区在线| 国产精品推荐精品| 欧美在线观看视频在线| 久久久国产成人精品| 伊人久久亚洲影院| 老司机免费视频久久| 亚洲人成亚洲人成在线观看| 一本大道av伊人久久综合| 欧美性大战久久久久久久| 亚洲一区在线观看免费观看电影高清| 欧美一区综合| 影音先锋亚洲视频| 欧美另类久久久品 | 久久精品国产一区二区三区免费看| 国产在线拍揄自揄视频不卡99| 久热这里只精品99re8久| 亚洲国产中文字幕在线观看| 亚洲一二三区在线观看| 国产精品久久7| 久久精品视频免费观看| 亚洲经典在线看| 久久av在线看| 一本色道久久99精品综合 | 久久久久免费视频| 99精品热视频| 久久在线免费观看| 亚洲视频在线观看一区| 国产一区91| 欧美日本不卡高清| 久久国产福利国产秒拍| 亚洲人成人99网站| 久久免费精品视频| 亚洲自拍偷拍福利| 亚洲高清一区二| 国产精品婷婷午夜在线观看| 欧美成在线观看| 欧美一级淫片aaaaaaa视频| 亚洲欧洲在线播放| 久久综合五月| 欧美影院视频| 亚洲免费小视频| 99精品福利视频| 一区二区在线观看av| 国产精品乱码| 欧美另类一区二区三区| 久色成人在线| 欧美在线播放一区| 亚洲欧美日韩综合一区| 99精品热视频只有精品10| 亚洲黄色高清| 欧美成人中文字幕在线| 久久久久久久999| 午夜久久99| 欧美一级视频| 亚洲欧美国产精品专区久久| 亚洲精品麻豆| 亚洲精品小视频| 亚洲精品影院在线观看| 亚洲激情第一页| 尤物在线观看一区| 樱桃成人精品视频在线播放| 国产麻豆精品久久一二三| 国产精品久久久久久久久| 欧美午夜精彩| 国产精品黄色| 国产精品久久久久久久一区探花 | 欧美精品一区二区三区久久久竹菊| 两个人的视频www国产精品| 久久久久久久999| 久久国产精品免费一区| 久久精品视频亚洲| 亚洲福利视频在线| 欧美国产第一页| 亚洲高清在线观看一区| 91久久精品网| aa级大片欧美| 亚洲欧美一区二区精品久久久| 亚洲综合电影一区二区三区| 欧美一区二区三区免费大片| 久久久精品一区| 美女主播一区| 欧美激情亚洲激情| 国产精品电影在线观看| 国产伦精品一区| 亚洲第一级黄色片| 日韩亚洲欧美成人一区| 亚洲直播在线一区| 久久综合色播五月| 亚洲国产一区二区a毛片| 一区二区电影免费观看| 亚洲欧美一级二级三级| 久久综合久久久| 欧美日韩国产在线播放| 国产精品社区| 亚洲国产成人高清精品| 亚洲图片在区色| 久久亚洲欧洲| 日韩亚洲不卡在线| 欧美一区二区女人| 欧美激情亚洲另类| 国产私拍一区| 亚洲精品123区| 性色av一区二区怡红| 欧美chengren| 亚洲午夜免费视频| 噜噜噜在线观看免费视频日韩| 欧美三级资源在线| 在线成人h网| 先锋影音一区二区三区| 欧美激情久久久| 欧美亚洲尤物久久| 欧美日韩久久不卡| 激情国产一区| 亚洲欧美日韩中文在线制服| 亚洲国产高清一区| 久久精品一区中文字幕| 欧美日韩一区二区免费在线观看| 国产一区二区三区久久| 一区二区电影免费观看| 美女脱光内衣内裤视频久久影院| 亚洲线精品一区二区三区八戒| 久久综合免费视频影院| 国产偷国产偷亚洲高清97cao | 黄网站免费久久| 欧美一区二区三区免费看| 亚洲日韩欧美视频| 蜜臀av一级做a爰片久久|