diff --git a/DesignPattern/AbstractFactoryPattern/Factory.cpp b/DesignPattern/AbstractFactoryPattern/Factory.cpp index 4ad2e7c..fcf5db8 100644 --- a/DesignPattern/AbstractFactoryPattern/Factory.cpp +++ b/DesignPattern/AbstractFactoryPattern/Factory.cpp @@ -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: diff --git a/DesignPattern/AbstractFactoryPattern/Factory.h b/DesignPattern/AbstractFactoryPattern/Factory.h index b00ed46..dd0b9a0 100644 --- a/DesignPattern/AbstractFactoryPattern/Factory.h +++ b/DesignPattern/AbstractFactoryPattern/Factory.h @@ -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 diff --git a/DesignPattern/AbstractFactoryPattern/FactoryMain.cpp b/DesignPattern/AbstractFactoryPattern/FactoryMain.cpp index b819e2d..30f5439 100644 --- a/DesignPattern/AbstractFactoryPattern/FactoryMain.cpp +++ b/DesignPattern/AbstractFactoryPattern/FactoryMain.cpp @@ -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(); @@ -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(); @@ -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(); diff --git a/DesignPattern/AbstractFactoryPattern/concrete_factory.h b/DesignPattern/AbstractFactoryPattern/concrete_factory.h index 8de0baf..45d7830 100644 --- a/DesignPattern/AbstractFactoryPattern/concrete_factory.h +++ b/DesignPattern/AbstractFactoryPattern/concrete_factory.h @@ -8,7 +8,7 @@ #include "Factory.h" #include "concrete_product.h" -// 奔驰工厂 +// Benz factory class BenzFactory : public Factory { public: @@ -22,7 +22,7 @@ public: } }; -// 宝马工厂 +// BMW factory class BmwFactory : public Factory { public: @@ -35,7 +35,7 @@ public: } }; -// 奥迪工厂 +// Audi factory class AudiFactory : public Factory { public: diff --git a/DesignPattern/AbstractFactoryPattern/concrete_product.h b/DesignPattern/AbstractFactoryPattern/concrete_product.h index fef09bb..b41fe8e 100644 --- a/DesignPattern/AbstractFactoryPattern/concrete_product.h +++ b/DesignPattern/AbstractFactoryPattern/concrete_product.h @@ -7,8 +7,8 @@ #include "product.h" -/********** 汽车 **********/ -// 奔驰 +/********** Car **********/ +// Benz class BenzCar : public ICar { public: @@ -18,7 +18,7 @@ public: } }; -// 宝马 +// BMW class BmwCar : public ICar { public: @@ -28,7 +28,7 @@ public: } }; -// 奥迪 +// Audi class AudiCar : public ICar { public: @@ -38,8 +38,8 @@ public: } }; -/********** 自行车 **********/ -// 奔驰 +/********** Bicycle **********/ +// Benz class BenzBike : public IBike { public: @@ -49,7 +49,7 @@ public: } }; -// 宝马 +// BMW class BmwBike : public IBike { public: @@ -59,7 +59,7 @@ public: } }; -// 奥迪 +// Audi class AudiBike : public IBike { public: diff --git a/DesignPattern/AbstractFactoryPattern/product.h b/DesignPattern/AbstractFactoryPattern/product.h index 4d62240..019c59f 100644 --- a/DesignPattern/AbstractFactoryPattern/product.h +++ b/DesignPattern/AbstractFactoryPattern/product.h @@ -8,14 +8,14 @@ #include using std::string; -// 汽车接口 +// Car Interface class ICar { public: virtual string Name() = 0; }; -// 自行车接口 +// Bike Interface class IBike { public: diff --git a/DesignPattern/AdapterPattern/AdapterMain.h b/DesignPattern/AdapterPattern/AdapterMain.h index 8e58cba..89931ea 100644 --- a/DesignPattern/AdapterPattern/AdapterMain.h +++ b/DesignPattern/AdapterPattern/AdapterMain.h @@ -9,10 +9,10 @@ void AdapterMain() { - // + // Create a power adapter IRussiaSocket * pAdapter = new PowerAdapter(); - // + // Recharge pAdapter->Charge(); SAFE_DELETE(pAdapter); diff --git a/DesignPattern/AdapterPattern/adaptee.h b/DesignPattern/AdapterPattern/adaptee.h index 679c378..e263725 100644 --- a/DesignPattern/AdapterPattern/adaptee.h +++ b/DesignPattern/AdapterPattern/adaptee.h @@ -7,7 +7,7 @@ #include -// 自带的充电器(两脚扁型) +// Built-in charger (two-leg flat type) class OwnCharger { public: diff --git a/DesignPattern/AdapterPattern/adapter.h b/DesignPattern/AdapterPattern/adapter.h index ecb94f5..a15a792 100644 --- a/DesignPattern/AdapterPattern/adapter.h +++ b/DesignPattern/AdapterPattern/adapter.h @@ -12,7 +12,7 @@ #define SAFE_DELETE(p) { if(p){delete(p); (p)=NULL;} } #endif -// 电源适配器 +// Power Adapter class PowerAdapter : public IRussiaSocket { public: @@ -23,11 +23,11 @@ public: } 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; }; diff --git a/DesignPattern/AdapterPattern/target.h b/DesignPattern/AdapterPattern/target.h index cbe7cfa..6025215 100644 --- a/DesignPattern/AdapterPattern/target.h +++ b/DesignPattern/AdapterPattern/target.h @@ -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; }; diff --git a/DesignPattern/BridgePattern/BridgeMain.cpp b/DesignPattern/BridgePattern/BridgeMain.cpp index 00324cd..e043562 100644 --- a/DesignPattern/BridgePattern/BridgeMain.cpp +++ b/DesignPattern/BridgePattern/BridgeMain.cpp @@ -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(); diff --git a/DesignPattern/BridgePattern/abstraction.h b/DesignPattern/BridgePattern/abstraction.h index 82cdd59..520a23a 100644 --- a/DesignPattern/BridgePattern/abstraction.h +++ b/DesignPattern/BridgePattern/abstraction.h @@ -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; diff --git a/DesignPattern/BridgePattern/concrete_implementor.h b/DesignPattern/BridgePattern/concrete_implementor.h index 35a2daa..c96e9c0 100644 --- a/DesignPattern/BridgePattern/concrete_implementor.h +++ b/DesignPattern/BridgePattern/concrete_implementor.h @@ -8,32 +8,32 @@ #include "implementor.h" #include -// 电灯 +// 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; diff --git a/DesignPattern/BridgePattern/implementor.h b/DesignPattern/BridgePattern/implementor.h index c8b801e..7cfaaff 100644 --- a/DesignPattern/BridgePattern/implementor.h +++ b/DesignPattern/BridgePattern/implementor.h @@ -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 diff --git a/DesignPattern/BridgePattern/refined_abstraction.h b/DesignPattern/BridgePattern/refined_abstraction.h index 48be107..3e8ecc1 100644 --- a/DesignPattern/BridgePattern/refined_abstraction.h +++ b/DesignPattern/BridgePattern/refined_abstraction.h @@ -8,43 +8,43 @@ #include "abstraction.h" #include -// 拉链式开关 +// 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(); } }; diff --git a/DesignPattern/ObserverPattern/ObserverMain.cpp b/DesignPattern/ObserverPattern/ObserverMain.cpp index cd536c7..b277418 100644 --- a/DesignPattern/ObserverPattern/ObserverMain.cpp +++ b/DesignPattern/ObserverPattern/ObserverMain.cpp @@ -6,25 +6,25 @@ void ObserverMain() { - // + // Create Subject ConcreteSubject * pSubject = new ConcreteSubject(); - // ۲ + // Create Observer IObserver * pObserver1 = new ConcreteObserver("Jack Ma"); IObserver * pObserver2 = new ConcreteObserver("Pony"); - // ע۲ + // Attach Observers pSubject->Attach(pObserver1); pSubject->Attach(pObserver2); - // ļ۸񣬲֪ͨ۲ + // Change the price and notify the observer pSubject->SetPrice(12.5); pSubject->Notify(); - // עһ۲ + // Detach Observers pSubject->Detach(pObserver2); - // ٴθ״̬֪ͨ۲ + // Change the state again and notify the observer pSubject->SetPrice(15.0); pSubject->Notify(); diff --git a/DesignPattern/ObserverPattern/concrete_observer.h b/DesignPattern/ObserverPattern/concrete_observer.h index 37a68b3..13c4b3c 100644 --- a/DesignPattern/ObserverPattern/concrete_observer.h +++ b/DesignPattern/ObserverPattern/concrete_observer.h @@ -19,7 +19,7 @@ public: } private: - std::string m_strName; // 名字 + std::string m_strName; // name }; #endif //DESIGNPATTERN_CONCRETE_OBSERVER_H diff --git a/DesignPattern/ObserverPattern/concrete_subject.h b/DesignPattern/ObserverPattern/concrete_subject.h index d05e98c..2ff0f03 100644 --- a/DesignPattern/ObserverPattern/concrete_subject.h +++ b/DesignPattern/ObserverPattern/concrete_subject.h @@ -10,7 +10,7 @@ #include #include -// 具体主题 +// Specific Subject class ConcreteSubject : public ISubject { public: @@ -27,7 +27,7 @@ public: { m_observers.remove(observer); } - // 通知所有观察者 + // Notify all observers void Notify() { std::list::iterator it = m_observers.begin(); @@ -38,8 +38,8 @@ public: } } private: - std::list m_observers; // 观察者列表 - float m_fPrice; // 价格 + std::list m_observers; // Observer list + float m_fPrice; // Price }; #endif //DESIGNPATTERN_CONCRETE_SUBJECT_H diff --git a/DesignPattern/ObserverPattern/observer.h b/DesignPattern/ObserverPattern/observer.h index 500c396..feabe85 100644 --- a/DesignPattern/ObserverPattern/observer.h +++ b/DesignPattern/ObserverPattern/observer.h @@ -5,11 +5,11 @@ #ifndef DESIGNPATTERN_OBSERVER_H #define DESIGNPATTERN_OBSERVER_H -// 抽象观察者 +// Abstract observer class IObserver { public: - virtual void Update(float price) = 0; // 更新价格 + virtual void Update(float price) = 0; // Update price }; #endif //DESIGNPATTERN_OBSERVER_H diff --git a/DesignPattern/ObserverPattern/subject.h b/DesignPattern/ObserverPattern/subject.h index 9d50fba..72d22cc 100644 --- a/DesignPattern/ObserverPattern/subject.h +++ b/DesignPattern/ObserverPattern/subject.h @@ -10,9 +10,9 @@ class IObserver; class ISubject { public: - virtual void Attach(IObserver *) = 0; // 注册观察者 - virtual void Detach(IObserver *) = 0; // 注销观察者 - virtual void Notify() = 0; // 通知观察者 + virtual void Attach(IObserver *) = 0; // Attach observer + virtual void Detach(IObserver *) = 0; // Detach observer + virtual void Notify() = 0; // Notify observer }; #endif //DESIGNPATTERN_SUBJECT_H diff --git a/DesignPattern/SingletonPattern/Singleton.h b/DesignPattern/SingletonPattern/Singleton.h index 79bc8ad..cb6df28 100644 --- a/DesignPattern/SingletonPattern/Singleton.h +++ b/DesignPattern/SingletonPattern/Singleton.h @@ -5,7 +5,7 @@ #ifndef DESIGNPATTERN_SINGLETON_H #define DESIGNPATTERN_SINGLETON_H -// 单例模式 +// Singleton mode class Singleton { private: Singleton(){}