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