The second of the design pattern of the liar

Source: Internet
Author: User

111.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <string> #include <iostream>using namespace Std;class person{private:string M_strname;public:person (String strName) {m_strname = StrName;} Person () {}virtual void Show () {cout << "dress up is:" << m_strname << Endl;}}; Class finery:p ublic person{protected:person* m_component;public:void decorate (person* component) {m_component = component;} virtual void Show () {m_component->show ();}}; Class Tshirt:p ublic finery{public:virtual void Show () {cout << "T shirts" << endl;m_component->show ();}}; Class Bigtrouser:p ublic finery{public:virtual void Show () {cout << "Big Trouser" << endl;m_component-> Show ();}}; int _tmain (int argc, _tchar* argv[]) {person* p = new Person ("Xiao Li"); bigtrouser* BT = new Bigtrouser (); tshirt* ts = new Tshirt (); bt->decorate (P); ts->decorate (BT); Ts->show (); return 0;}

  

Two of the big talk design patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.