Skip to content

Commit

Permalink
Design mode code comments are changed to English
Browse files Browse the repository at this point in the history
  • Loading branch information
huihut committed Dec 16, 2020
1 parent 8fe5157 commit 3a9e212
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions DesignPattern/AbstractFactoryPattern/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Factory* Factory::CreateFactory(FACTORY_TYPE factory)
{
Factory *pFactory = nullptr;
switch (factory) {
case FACTORY_TYPE::BENZ_FACTORY: // 奔驰工厂
case FACTORY_TYPE::BENZ_FACTORY: // Benz factory
pFactory = new BenzFactory();
break;
case FACTORY_TYPE::BMW_FACTORY: // 宝马工厂
case FACTORY_TYPE::BMW_FACTORY: // BMW factory
pFactory = new BmwFactory();
break;
case FACTORY_TYPE::AUDI_FACTORY: // 奥迪工厂
case FACTORY_TYPE::AUDI_FACTORY: // Audi factory
pFactory = new AudiFactory();
break;
default:
Expand Down
14 changes: 7 additions & 7 deletions DesignPattern/AbstractFactoryPattern/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

#include "product.h"

// 抽象工厂模式
// Abstract factory pattern
class Factory {
public:
enum FACTORY_TYPE {
BENZ_FACTORY, // 奔驰工厂
BMW_FACTORY, // 宝马工厂
AUDI_FACTORY // 奥迪工厂
BENZ_FACTORY, // Benz factory
BMW_FACTORY, // BMW factory
AUDI_FACTORY // Audi factory
};

virtual ICar* CreateCar() = 0; // 生产汽车
virtual IBike* CreateBike() = 0; // 生产自行车
static Factory * CreateFactory(FACTORY_TYPE factory); // 创建工厂
virtual ICar* CreateCar() = 0; // Production car
virtual IBike* CreateBike() = 0; // Production bicycle
static Factory * CreateFactory(FACTORY_TYPE factory); // Create factory
};

#endif //DESIGNPATTERN_FACTORY_H
6 changes: 3 additions & 3 deletions DesignPattern/AbstractFactoryPattern/FactoryMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;

void FactoryMain()
{
// ąźłŰ
// Benz
Factory * pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::BENZ_FACTORY);
ICar * pCar = pFactory->CreateCar();
IBike * pBike = pFactory->CreateBike();
Expand All @@ -22,7 +22,7 @@ void FactoryMain()
SAFE_DELETE(pBike);
SAFE_DELETE(pFactory);

// ąŚÂí
// BMW
pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::BMW_FACTORY);
pCar = pFactory->CreateCar();
pBike = pFactory->CreateBike();
Expand All @@ -33,7 +33,7 @@ void FactoryMain()
SAFE_DELETE(pBike);
SAFE_DELETE(pFactory);

// °ÂľĎ
// Audi
pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::AUDI_FACTORY);
pCar = pFactory->CreateCar();
pBike = pFactory->CreateBike();
Expand Down
6 changes: 3 additions & 3 deletions DesignPattern/AbstractFactoryPattern/concrete_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Factory.h"
#include "concrete_product.h"

// 奔驰工厂
// Benz factory
class BenzFactory : public Factory
{
public:
Expand All @@ -22,7 +22,7 @@ class BenzFactory : public Factory
}
};

// 宝马工厂
// BMW factory
class BmwFactory : public Factory
{
public:
Expand All @@ -35,7 +35,7 @@ class BmwFactory : public Factory
}
};

// 奥迪工厂
// Audi factory
class AudiFactory : public Factory
{
public:
Expand Down
16 changes: 8 additions & 8 deletions DesignPattern/AbstractFactoryPattern/concrete_product.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include "product.h"

/********** 汽车 **********/
// 奔驰
/********** Car **********/
// Benz
class BenzCar : public ICar
{
public:
Expand All @@ -18,7 +18,7 @@ class BenzCar : public ICar
}
};

// 宝马
// BMW
class BmwCar : public ICar
{
public:
Expand All @@ -28,7 +28,7 @@ class BmwCar : public ICar
}
};

// 奥迪
// Audi
class AudiCar : public ICar
{
public:
Expand All @@ -38,8 +38,8 @@ class AudiCar : public ICar
}
};

/********** 自行车 **********/
// 奔驰
/********** Bicycle **********/
// Benz
class BenzBike : public IBike
{
public:
Expand All @@ -49,7 +49,7 @@ class BenzBike : public IBike
}
};

// 宝马
// BMW
class BmwBike : public IBike
{
public:
Expand All @@ -59,7 +59,7 @@ class BmwBike : public IBike
}
};

// 奥迪
// Audi
class AudiBike : public IBike
{
public:
Expand Down
4 changes: 2 additions & 2 deletions DesignPattern/AbstractFactoryPattern/product.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <string>
using std::string;

// 汽车接口
// Car Interface
class ICar
{
public:
virtual string Name() = 0;
};

// 自行车接口
// Bike Interface
class IBike
{
public:
Expand Down
4 changes: 2 additions & 2 deletions DesignPattern/AdapterPattern/AdapterMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

void AdapterMain()
{
// ´´½¨ÊÊÅäÆ÷
// Create a power adapter
IRussiaSocket * pAdapter = new PowerAdapter();

// ³äµç
// Recharge
pAdapter->Charge();

SAFE_DELETE(pAdapter);
Expand Down
2 changes: 1 addition & 1 deletion DesignPattern/AdapterPattern/adaptee.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <iostream>

// 自带的充电器(两脚扁型)
// Built-in charger (two-leg flat type)
class OwnCharger
{
public:
Expand Down
6 changes: 3 additions & 3 deletions DesignPattern/AdapterPattern/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define SAFE_DELETE(p) { if(p){delete(p); (p)=NULL;} }
#endif

// 电源适配器
// Power Adapter
class PowerAdapter : public IRussiaSocket
{
public:
Expand All @@ -23,11 +23,11 @@ class PowerAdapter : public IRussiaSocket
}
void Charge()
{
// 使用自带的充电器(两脚扁形)充电
// Use the built-in charger (two-pin flat) to charge
m_pCharger->ChargeWithFeetFlat();
}
private:
// 持有需要被适配的接口对象(自带的充电器)
// Hold the interface object that needs to be adapted (the built-in charger)
OwnCharger* m_pCharger;
};

Expand Down
4 changes: 2 additions & 2 deletions DesignPattern/AdapterPattern/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#ifndef DESIGNPATTERN_TARGET_H
#define DESIGNPATTERN_TARGET_H

// 俄罗斯提供的插座
// Sockets provided by Russia
class IRussiaSocket
{
public:
// 使用双脚圆形充电(暂不实现)
// Use both feet to charge in a round shape (not implemented yet)
virtual void Charge() = 0;
};

Expand Down
10 changes: 5 additions & 5 deletions DesignPattern/BridgePattern/BridgeMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

void BridgeMain()
{
// 创建电器(电灯、电风扇)
// Create electrical appliances (electric lights, electric fans)
IElectricalEquipment * light = new Light();
IElectricalEquipment * fan = new Fan();

// 创建开关(拉链式开关、两位开关)
// 将拉链式开关和电灯关联起来,两位开关和风扇关联起来
// 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);

// 开灯、关灯
// Lights on, lights off
pullChain->On();
pullChain->Off();

// 打开风扇、关闭风扇
// Turn on the fan, turn off the fan
twoPosition->On();
twoPosition->Off();

Expand Down
6 changes: 3 additions & 3 deletions DesignPattern/BridgePattern/abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions DesignPattern/BridgePattern/concrete_implementor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions DesignPattern/BridgePattern/implementor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions DesignPattern/BridgePattern/refined_abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down
Loading

0 comments on commit 3a9e212

Please sign in to comment.