aggregation //how difficult to say =D
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
virtual void print()=0;
protected:
string name;
};
class Lee:public Person
{
public:
Lee() { name="Bruce Lee"; }
void print() {cout<<"name: "<<name<<endl; }
};
class Chan:public Person
{
public:
Chan() { name="Jackie Chan"; }
void print() {cout<<"name: "<<name<<endl; }
};
class Car
{
public:
virtual void printCar()=0;
protected:
string model;
};
class Audi:public Car
{
public:
Audi() { model="AUDI"; }
void printCar() { cout<<"model: "<<model<<endl; }
};
class Mazda:public Car
{
public:
Mazda() { model="MAZDA"; }
void printCar() { cout<<"model: "<<model<<endl; }
};
class Follow
{
public:
void setPerson(Person *k)
{
this->p=k;
}
void setCar(Car *m)
{
this->c=m;
}
void show()
{
cout<<"there are ''car'' and ''character'' details that you use: "<<endl;
c->printCar();
p->print();
}
protected:
Person *p;
Car *c;
};
int main()
{
Follow *f=new Follow();
Car *car=new Audi();
Person *person=new Lee();
f->setCar(car);
f->setPerson(person);
f->show();
cout<<"###############################"<<endl;
car=new Mazda();
person=new Chan();
f->setCar(car);
f->setPerson(person);
f->show();
system("pause");
return 0;
}