forked from huihut/interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refined_abstraction.h
53 lines (43 loc) · 1.25 KB
/
refined_abstraction.h
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
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by xiemenghui on 2018/7/21.
//
#ifndef DESIGNPATTERN_REFINED_ABSTRACTION_H
#define DESIGNPATTERN_REFINED_ABSTRACTION_H
#include "abstraction.h"
#include <iostream>
// 拉链式开关
class PullChainSwitch : public ISwitch
{
public:
PullChainSwitch(IElectricalEquipment *ee) : ISwitch(ee) {}
// 用拉链式开关打开电器
virtual void On() override
{
std::cout << "Switch on the equipment with a pull chain switch." << std::endl;
m_pEe->PowerOn();
}
// 用拉链式开关关闭电器
virtual void Off() override
{
std::cout << "Switch off the equipment with a pull chain switch." << std::endl;
m_pEe->PowerOff();
}
};
// 两位开关
class TwoPositionSwitch : public ISwitch
{
public:
TwoPositionSwitch(IElectricalEquipment *ee) : ISwitch(ee) {}
// 用两位开关打开电器
virtual void On() override
{
std::cout << "Switch on the equipment with a two-position switch." << std::endl;
m_pEe->PowerOn();
}
// 用两位开关关闭电器
virtual void Off() override {
std::cout << "Switch off the equipment with a two-position switch." << std::endl;
m_pEe->PowerOff();
}
};
#endif //DESIGNPATTERN_REFINED_ABSTRACTION_H