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

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 常興龍 閱讀(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  回復  更多評論
  

# 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>
            国产欧美一区二区三区在线老狼| 欧美亚洲免费电影| 麻豆国产va免费精品高清在线| 国产日韩一区| 久久精品中文字幕一区二区三区| 亚洲欧美日韩国产一区二区| 国产色婷婷国产综合在线理论片a| 欧美一区在线直播| 久久精品一二三区| 亚洲精品欧美极品| 一区二区精品国产| 国产一区二区三区四区老人| 免费在线观看精品| 欧美福利专区| 校园激情久久| 久久久最新网址| 在线视频日本亚洲性| 午夜精品999| 日韩视频在线观看国产| 亚洲线精品一区二区三区八戒| 国产欧美一区二区精品忘忧草 | 欧美精品一卡| 亚洲欧美综合v| 免费在线观看成人av| 亚洲综合色在线| 毛片基地黄久久久久久天堂| 国产欧美日韩伦理| 国产精品美女主播在线观看纯欲| 久久国产福利国产秒拍| 欧美高清在线精品一区| 性欧美大战久久久久久久免费观看| 久久久久久穴| 午夜精品久久久久久久| 欧美1区2区| 久久久久久综合网天天| 国产精品久久久免费 | 亚洲激情电影中文字幕| 亚洲直播在线一区| 一二三区精品福利视频| 久久久久久久精| 欧美在线观看天堂一区二区三区| 欧美精品粉嫩高潮一区二区| 久久夜色精品国产欧美乱| 国产精品国产自产拍高清av| 亚洲电影第1页| 国产综合在线视频| 亚洲欧美日韩精品久久| 亚洲一区二区三区欧美| 欧美成人蜜桃| 欧美成人精品福利| 国产一区二区三区免费在线观看| 亚洲一区二区三区乱码aⅴ| 亚洲精品国产系列| 欧美国产日韩一区二区| 欧美1区免费| 怡红院精品视频在线观看极品| 亚洲一区欧美激情| 亚洲欧美在线观看| 国产精品久久久久毛片软件| 99re视频这里只有精品| 在线视频你懂得一区二区三区| 欧美成人精品| 亚洲国产1区| 亚洲人午夜精品| 欧美日韩成人一区二区三区| 亚洲高清不卡一区| 日韩一级免费| 欧美日韩精品免费观看| 日韩一级精品视频在线观看| 一区二区三区四区精品| 欧美日韩中文字幕在线| 一本久道久久综合狠狠爱| 亚洲一区二区三区激情| 国产精品国产三级国产专播品爱网| 宅男在线国产精品| 欧美中文字幕精品| 韩国三级电影一区二区| 免费美女久久99| 日韩写真在线| 欧美一区久久| 在线观看视频欧美| 欧美日韩一区二区免费在线观看 | 欧美激情亚洲| aa亚洲婷婷| 国产精品亚洲片夜色在线| 午夜欧美电影在线观看| 欧美大片91| 中文欧美日韩| 国产一区二区三区高清| 老牛嫩草一区二区三区日本| 欧美激情一区二区三区不卡| 亚洲一区欧美| 免费视频一区| 久久国产精品久久久久久电车| 国模精品一区二区三区| 免费成人美女女| 一区二区激情| 欧美国产视频日韩| 亚洲欧美bt| 亚洲国产毛片完整版 | 亚洲电影av| 亚洲欧美日本另类| 亚洲电影网站| 国产精品久久久99| 免费在线观看精品| 午夜精品区一区二区三| 亚洲国产天堂久久国产91| 亚洲欧美日韩视频一区| 91久久中文| 在线播放日韩专区| 国产精品一区二区久久久| 免费在线看成人av| 羞羞色国产精品| 一区二区免费在线视频| 欧美高清一区| 老牛影视一区二区三区| 亚洲字幕在线观看| 一本色道久久99精品综合| 在线观看日韩av| 国产亚洲福利社区一区| 欧美视频亚洲视频| 欧美伦理91| 免费观看日韩av| 久久亚洲免费| 午夜精品一区二区三区在线视| 99精品国产在热久久下载| 欧美韩国日本一区| 免费成人在线视频网站| 久久久久久久久岛国免费| 亚洲欧美日韩一区二区三区在线观看 | 欧美日本不卡高清| 欧美成人精品福利| 老司机67194精品线观看| 久久国产高清| 欧美在现视频| 久久精品理论片| 午夜亚洲视频| 性欧美长视频| 欧美在线高清| 久久国产欧美| 久久久久久久久伊人| 欧美在线播放一区二区| 久久精品三级| 久久人人爽人人| 麻豆精品网站| 欧美激情四色 | 午夜精彩国产免费不卡不顿大片| 亚洲小视频在线观看| 亚洲伊人伊色伊影伊综合网| 亚洲私人影吧| 欧美一级二区| 久久久亚洲一区| 另类春色校园亚洲| 欧美激情aⅴ一区二区三区| 欧美伦理在线观看| 国产精品久久国产愉拍| 国产精品永久入口久久久| 国产视频久久| 亚洲电影第1页| 99精品久久免费看蜜臀剧情介绍| 宅男噜噜噜66一区二区| 玖玖玖国产精品| 欧美日韩一区二区三区免费看| 久久综合伊人| 欧美日韩爆操| 国产无一区二区| 亚洲激情网址| 亚洲欧美日本伦理| 快she精品国产999| 亚洲精品久久久久中文字幕欢迎你| 日韩视频免费| 欧美中文日韩| 欧美日韩成人综合在线一区二区| 国产精品国产三级国产普通话蜜臀| 国产一区二区三区免费在线观看| 亚洲国产欧美久久| 午夜国产一区| 欧美激情91| 亚洲免费在线观看视频| 美女啪啪无遮挡免费久久网站| 欧美日韩理论| 在线免费日韩片| 午夜影院日韩| 亚洲国产日韩综合一区| 欧美一级午夜免费电影| 欧美精彩视频一区二区三区| 国产人妖伪娘一区91| 亚洲人成欧美中文字幕| 久久精品亚洲国产奇米99| 亚洲国产日韩在线| 久久成人免费视频| 国产精品久久久久久久久久久久| 雨宫琴音一区二区在线| 午夜日韩福利| 亚洲精品久久久久久久久久久| 欧美在线视频观看| 国产精品久久久91| 制服丝袜亚洲播放| 亚洲欧洲一区二区三区| 久久人人97超碰国产公开结果|