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

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>
            亚洲一区二区三区四区中文| 亚洲狼人综合| 久久精品国产精品亚洲综合| 国产一区二区中文| 久久这里有精品15一区二区三区| 久久九九国产| 日韩午夜免费视频| 男女激情视频一区| 亚洲风情亚aⅴ在线发布| 欧美高清不卡| 欧美日韩视频在线| 亚洲欧美日韩一区二区三区在线| 亚洲欧美成人精品| 在线日韩中文| 一区二区三区偷拍| 国内视频一区| 日韩网站在线| 国内一区二区三区| 亚洲激情小视频| 国产精品久久一区二区三区| 久久伊人一区二区| 欧美日韩精品一区二区在线播放 | 亚洲国产精品成人| 一区二区三区日韩| 一区二区亚洲欧洲国产日韩| 亚洲精品一区二区在线观看| 国产日韩在线视频| 亚洲黑丝在线| 国产真实乱偷精品视频免| 亚洲国产精品t66y| 国产美女一区| 日韩亚洲欧美中文三级| 国语自产精品视频在线看| 一区二区三区波多野结衣在线观看| 国产一区二区三区在线播放免费观看| 亚洲人成在线观看| 激情五月婷婷综合| 亚洲一区二区视频在线观看| 亚洲精品一区二区三| 欧美一区二区在线| 亚洲永久免费精品| 欧美精品免费看| 免费永久网站黄欧美| 国产色综合网| 一区二区三区四区蜜桃| 亚洲精品久久| 欧美jjzz| 亚洲成人直播| 在线观看亚洲| 欧美在线观看视频| 欧美一区二区三区视频在线观看 | 久久久久久97三级| 欧美一级成年大片在线观看| 欧美日韩亚洲一区在线观看| 亚洲第一主播视频| 亚洲国产欧美久久| 久热国产精品| 免播放器亚洲一区| 在线电影欧美日韩一区二区私密| 午夜精品一区二区三区四区| 久久激情视频久久| 国产精品日韩精品欧美精品| 亚洲午夜激情网页| 亚洲综合导航| 欧美日韩在线视频一区| av成人免费观看| 中文av一区二区| 欧美系列亚洲系列| 亚洲一二区在线| 久久精品女人| 亚洲午夜视频在线| 国产精品国产馆在线真实露脸| 99成人精品| 欧美在线观看一区| 国产九区一区在线| 久久超碰97中文字幕| 麻豆国产精品一区二区三区| 亚洲激情中文1区| 欧美精品1区2区| 夜夜夜久久久| 欧美一区二区免费观在线| 国产一区二区三区高清| 久久精品91| 亚洲国产综合视频在线观看| 一区二区三区四区在线| 国产精品久久久久久亚洲调教| 午夜精品理论片| 欧美成熟视频| 一区二区三区|亚洲午夜| 国产精品美女久久久久aⅴ国产馆| 亚洲综合精品自拍| 蜜桃av综合| 亚洲色在线视频| 国产日韩综合一区二区性色av| 可以看av的网站久久看| 亚洲蜜桃精久久久久久久| 欧美在线黄色| 亚洲精品视频免费观看| 欧美午夜激情小视频| 久久精品国产欧美亚洲人人爽| 亚洲国产精品电影在线观看| 欧美在线看片| 99国产精品视频免费观看一公开| 国产精品无码专区在线观看| 久久伊伊香蕉| 亚洲欧美国产另类| 亚洲国产精品一区二区www在线| 性欧美xxxx视频在线观看| 亚洲国产合集| 国产日韩欧美高清| 欧美日韩免费一区二区三区| 久久成人人人人精品欧| 在线亚洲欧美| 亚洲激情电影在线| 久久中文精品| 欧美一区久久| 亚洲欧美日韩成人高清在线一区| 亚洲高清不卡一区| 国产免费成人| 国产精品不卡在线| 欧美精品在线播放| 久久亚洲色图| 久久精品日产第一区二区三区 | 欧美1区2区视频| 久久av资源网站| 亚洲欧美日韩国产成人| 亚洲乱码国产乱码精品精可以看 | 欧美激情一区二区三区全黄| 久久国产精品99国产精| 亚洲综合色丁香婷婷六月图片| 亚洲高清在线观看| 黄色成人av网站| 狠狠色丁香婷婷综合久久片| 国产日本欧美在线观看| 国产精品热久久久久夜色精品三区 | 美女国产一区| 欧美一级淫片播放口| 亚洲午夜久久久久久久久电影网| 亚洲精品小视频在线观看| 亚洲成人资源网| 欧美成人免费小视频| 欧美xx视频| 欧美激情免费观看| 亚洲风情在线资源站| 欧美成在线视频| 欧美岛国在线观看| 欧美高清视频一区二区三区在线观看| 久久手机精品视频| 免费日韩视频| 欧美激情综合色| 亚洲人成网站精品片在线观看| 亚洲人成网在线播放| 亚洲欧洲精品一区二区三区| 亚洲区一区二| 99国产精品久久久久老师| 一区二区久久久久| 在线视频一区二区| 小嫩嫩精品导航| 久久久久一区二区| 欧美成人综合一区| 欧美日韩一区二区三区免费看 | 久久精品国产免费| 蜜桃久久精品乱码一区二区| 欧美激情视频网站| 国产精品99免费看 | 午夜精品久久久久久久久久久久久 | 亚洲精品一区二区三区av| 亚洲乱码国产乱码精品精| 99视频国产精品免费观看| 亚洲天堂网在线观看| 欧美一级大片在线免费观看| 久久综合成人精品亚洲另类欧美| 欧美激情一区二区久久久| 国产精品青草综合久久久久99| 狠狠色狠狠色综合人人| 日韩午夜在线视频| 欧美在线影院| 亚洲黄色一区| 亚洲欧洲99久久| 蘑菇福利视频一区播放| 国产精品免费aⅴ片在线观看| 黄色一区二区在线观看| 99在线|亚洲一区二区| 久久不见久久见免费视频1| 欧美大成色www永久网站婷| 一区二区黄色| 免费亚洲电影在线观看| 国产精品亚洲一区| 亚洲精品一区二区三区不| 欧美在线观看网站| 日韩一二三在线视频播| 久久久7777| 国产精品日本一区二区| 亚洲欧洲日产国产综合网| 久久动漫亚洲| 一区二区三区国产在线| 免费在线一区二区| 国内精品视频一区| 亚洲在线免费观看| 亚洲欧洲精品天堂一级|