Design mode code comments are changed to English

https://github.com/huihut/interview/pull/73
This commit is contained in:
huihut
2020-12-16 16:07:24 +08:00
parent 8fe5157ae3
commit 3a9e2123aa
21 changed files with 78 additions and 78 deletions

View File

@@ -6,20 +6,20 @@
void BridgeMain()
{
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>
// Create electrical appliances (electric lights, electric fans)
IElectricalEquipment * light = new Light();
IElectricalEquipment * fan = new Fan();
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>غ͵<EFBFBD><EFBFBD>ƹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>غͷ<EFBFBD><EFBFBD>ȹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Create switch (pull chain switch, two-position switch)
// Associating a pull chain switch with a light and a two-position switch with a fan
ISwitch * pullChain = new PullChainSwitch(light);
ISwitch * twoPosition = new TwoPositionSwitch(fan);
// <EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD><EFBFBD>ص<EFBFBD>
// Lights on, lights off
pullChain->On();
pullChain->Off();
// <EFBFBD>򿪷<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>رշ<EFBFBD><EFBFBD><EFBFBD>
// Turn on the fan, turn off the fan
twoPosition->On();
twoPosition->Off();

View File

@@ -7,14 +7,14 @@
#include "implementor.h"
// 开关
// Switch
class ISwitch
{
public:
ISwitch(IElectricalEquipment *ee){ m_pEe = ee; }
virtual ~ISwitch(){}
virtual void On() = 0; // 打开电器
virtual void Off() = 0; // 关闭电器
virtual void On() = 0; // Turn on the appliance
virtual void Off() = 0; // Turn off the appliance
protected:
IElectricalEquipment * m_pEe;

View File

@@ -8,32 +8,32 @@
#include "implementor.h"
#include <iostream>
// 电灯
// Electric lights
class Light : public IElectricalEquipment
{
public:
// 开灯
// Turn on the lights
virtual void PowerOn() override
{
std::cout << "Light is on." << std::endl;
}
// 关灯
// Turn off the lights
virtual void PowerOff() override
{
std::cout << "Light is off." << std::endl;
}
};
// 风扇
// Electric Fan
class Fan : public IElectricalEquipment
{
public:
// 打开风扇
// Turn on the fan
virtual void PowerOn() override
{
std::cout << "Fan is on." << std::endl;
}
//关闭风扇
// Turn off the fan
virtual void PowerOff() override
{
std::cout << "Fan is off." << std::endl;

View File

@@ -5,13 +5,13 @@
#ifndef DESIGNPATTERN_IMPLEMENTOR_H
#define DESIGNPATTERN_IMPLEMENTOR_H
// 电器
// Electric equipment
class IElectricalEquipment
{
public:
virtual ~IElectricalEquipment(){}
virtual void PowerOn() = 0; // 打开
virtual void PowerOff() = 0; // 关闭
virtual void PowerOn() = 0;
virtual void PowerOff() = 0;
};
#endif //DESIGNPATTERN_IMPLEMENTOR_H

View File

@@ -8,43 +8,43 @@
#include "abstraction.h"
#include <iostream>
// 拉链式开关
// Zipper switch
class PullChainSwitch : public ISwitch
{
public:
PullChainSwitch(IElectricalEquipment *ee) : ISwitch(ee) {}
// 用拉链式开关打开电器
// Turn on the equipment with a zipper switch
virtual void On() override
{
std::cout << "Switch on the equipment with a pull chain switch." << std::endl;
std::cout << "Turn on the equipment with a zipper switch." << std::endl;
m_pEe->PowerOn();
}
// 用拉链式开关关闭电器
// Turn off the equipment with a zipper switch
virtual void Off() override
{
std::cout << "Switch off the equipment with a pull chain switch." << std::endl;
std::cout << "Turn off the equipment with a zipper switch." << std::endl;
m_pEe->PowerOff();
}
};
// 两位开关
// Two-position switch
class TwoPositionSwitch : public ISwitch
{
public:
TwoPositionSwitch(IElectricalEquipment *ee) : ISwitch(ee) {}
// 用两位开关打开电器
// Turn on the equipment with a two-position switch
virtual void On() override
{
std::cout << "Switch on the equipment with a two-position switch." << std::endl;
std::cout << "Turn on the equipment with a two-position switch." << std::endl;
m_pEe->PowerOn();
}
// 用两位开关关闭电器
// Turn off the equipment with a two-position switch
virtual void Off() override {
std::cout << "Switch off the equipment with a two-position switch." << std::endl;
std::cout << "Turn off the equipment with a two-position switch." << std::endl;
m_pEe->PowerOff();
}
};