C++ Design Pattern:Adapter

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

From this day onwards,I will start to learn C++ Design pattern.& I will write down my comprehensions and feelings.(for the purpose of self-examination,and communicating with newbies as me.)

(Adapterd from lxgljj's article in JAVA.)

#include <iostream>

#include <string>

using namespace std;

class PostedBook

{

public:

PostedBook( const string& rhs)

{

this->m_StringNO_ = rhs;

}

PostedBook( const PostedBook& rhs )

{

this->m_StringNO_ = rhs.m_StringNO_;

}

const PostedBook& operator=( const PostedBook& rhs )

{

this->m_StringNO_ = rhs.m_StringNO_;

return *this;

}

string GetPhoneNoFromBook()

{

return ( m_StringNO_ );

}

private:

string m_StringNO_;

};

class TellFriend

{

public:

void TellSth()

{

cout<<"Azure's phone number: ";

}

};

class TellFriendPhoneNo:public TellFriend

{

public:

TellFriendPhoneNo( const PostedBook& pb ):m_PostedBook_(pb)

{

//Nothing needed to be done.

}

void TellPhoneNumber()

{

cout<<m_PostedBook_.GetPhoneNoFromBook()<<endl;

}

private:

PostedBook m_PostedBook_;

};

int main()

{

PostedBook pb("13973284801");

TellFriendPhoneNo gp(pb);

gp.TellSth();

gp.TellPhoneNumber();

return (1);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航