2019-10-24 00:32:55 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "CompositePattern.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
Component *head, *sichuanBranch, *cdBranch, *myBranch, *office1, *office2, *office3,
|
|
|
|
*office4, *office5, *office6, *office7, *office8;
|
|
|
|
|
2021-10-28 13:58:09 +00:00
|
|
|
head = new SubComponent("总部");
|
|
|
|
sichuanBranch = new SubComponent("四川分部");
|
|
|
|
office1 = new AdminOffice("行政办公室");
|
|
|
|
office2 = new DeanOffice("教务办公室");
|
2019-10-24 00:32:55 +00:00
|
|
|
|
|
|
|
|
2021-10-28 13:58:09 +00:00
|
|
|
cdBranch = new SubComponent("成都分部");
|
|
|
|
myBranch = new SubComponent("绵阳分部");
|
|
|
|
office3 = new AdminOffice("行政办公室");
|
|
|
|
office4 = new DeanOffice("教务办公室");
|
2019-10-24 00:32:55 +00:00
|
|
|
|
|
|
|
|
2021-10-28 13:58:09 +00:00
|
|
|
office5 = new AdminOffice("行政办公室");
|
|
|
|
office6 = new DeanOffice("教务办公室");
|
2019-10-24 00:32:55 +00:00
|
|
|
|
2021-10-28 13:58:09 +00:00
|
|
|
office7 = new AdminOffice("行政办公室");
|
|
|
|
office8 = new DeanOffice("教务办公室");
|
2019-10-24 00:32:55 +00:00
|
|
|
|
|
|
|
cdBranch->add(office5);
|
|
|
|
cdBranch->add(office6);
|
|
|
|
|
|
|
|
myBranch->add(office7);
|
|
|
|
myBranch->add(office8);
|
|
|
|
|
|
|
|
sichuanBranch->add(office3);
|
|
|
|
sichuanBranch->add(office4);
|
|
|
|
sichuanBranch->add(cdBranch);
|
|
|
|
sichuanBranch->add(myBranch);
|
|
|
|
|
|
|
|
head->add(office1);
|
|
|
|
head->add(office2);
|
|
|
|
head->add(sichuanBranch);
|
|
|
|
|
|
|
|
head->operation();
|
|
|
|
|
|
|
|
system("pause");
|
2020-11-29 05:40:29 +00:00
|
|
|
|
|
|
|
delete head;
|
|
|
|
delete sichuanBranch;
|
|
|
|
delete cdBranch;
|
|
|
|
delete myBranch;
|
|
|
|
delete office1;
|
|
|
|
delete office2;
|
|
|
|
delete office3;
|
|
|
|
delete office4;
|
|
|
|
delete office5;
|
|
|
|
delete office6;
|
|
|
|
delete office7;
|
|
|
|
delete office8;
|
|
|
|
|
2019-10-24 00:32:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|