C++ Design Pattern:Adapter

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 bluejugar 的 blog

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);
}

本文关键:C++ Design Pattern:Adapter
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top