C ++ Design Pattern: Adapter

xiaoxiao2021-03-06  87

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 #include 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);

转载请注明原文地址:https://www.9cbs.com/read-98286.html

New Post(0)