#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
class Hand
{
public:
void Get()
{
cout << "取东西" << "\t";
}
};
class Leg
{
public:
void Run()
{
cout << "奔跑" << "\t";
}
};
class Eyes
{
public:
void See()
{
cout << "看" << "\t";
}
};
class Mouth
{
public:
void Eat()
{
cout << "吃东西" << "\t";
}
};
/*
人体是由各种器官组成,人如果要完成各种动作,则需要各个器官配合。
正好契合了外观模式
*/
class Person
{
private:
Hand *hand;
Eyes *eyes;
Mouth *mouth;
Leg *leg;
public:
Person()
{
eyes = new Eyes;
hand = new Hand;
mouth = new Mouth;
leg = new Leg;
}
void Eat()
{
cout << "开始进食" << endl;
hand->Get();
mouth->Eat();
cout << endl;
}
void Run()
{
cout << "开始跑步" << endl;
eyes->See();
leg->Run();
cout << endl;
}
};
int main()
{
Person *person = new Person;
person->Eat();
person->Run();
return 0;
}