forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (34 loc) · 914 Bytes
/
main.cpp
File metadata and controls
41 lines (34 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include "FlyweightPattern.h"
int main()
{
NetDeviceFactory *factory = NetDeviceFactory::getFactory();
NetDevice *device1, *device2, *device3, *device4;
// 客户端2获取一个hub
device1 = factory->getNetDevice('H');
device1->print(1);
// 客户端2获取一个hub
device2 = factory->getNetDevice('H');
device2->print(2);
// 判断两个hub是否是同一个
printf("判断两个hub是否是同一个:\n");
printf("device1:%p\ndevice2:%p\n", device1, device2);
printf("\n\n\n\n");
// 客户端3获取一个switch
device3 = factory->getNetDevice('S');
device3->print(1);
// 客户端4获取一个hub
device4 = factory->getNetDevice('S');
device4->print(2);
// 判断两个hub是否是同一个
printf("判断两个switch是否是同一个:\n");
printf("device3:%p\ndevice4:%p\n", device3, device4);
printf("\n\n");
delete factory;
delete device1;
delete device2;
delete device3;
delete device4;
system("pause");
return 0;
}