forked from huihut/interview
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgeMain.cpp
More file actions
Latest commit
30 lines (24 loc) · 666 Bytes
/
Copy pathBridgeMain.cpp
File metadata and controls
30 lines (24 loc) · 666 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
//
// Created by xiemenghui on 2018/7/21.
//
#include"BridgeMain.h"
voidBridgeMain()
{
// 创建电器(电灯、电风扇)
IElectricalEquipment * light = newLight();
IElectricalEquipment * fan = newFan();
// 创建开关(拉链式开关、两位开关)
// 将拉链式开关和电灯关联起来,两位开关和风扇关联起来
ISwitch * pullChain = newPullChainSwitch(light);
ISwitch * twoPosition = newTwoPositionSwitch(fan);
// 开灯、关灯
pullChain->On();
pullChain->Off();
// 打开风扇、关闭风扇
twoPosition->On();
twoPosition->Off();
SAFE_DELETE(twoPosition);
SAFE_DELETE(pullChain);
SAFE_DELETE(fan);
SAFE_DELETE(light);
}