mirror of
https://github.com/huihut/interview.git
synced 2025-12-18 13:04:38 +03:00
Design mode code comments are changed to English
https://github.com/huihut/interview/pull/73
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -10,7 +10,7 @@ using namespace std;
|
||||
|
||||
void FactoryMain()
|
||||
{
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 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);
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 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);
|
||||
|
||||
// <EFBFBD>µ<EFBFBD>
|
||||
// Audi
|
||||
pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::AUDI_FACTORY);
|
||||
pCar = pFactory->CreateCar();
|
||||
pBike = pFactory->CreateBike();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
// 汽车接口
|
||||
// Car Interface
|
||||
class ICar
|
||||
{
|
||||
public:
|
||||
virtual string Name() = 0;
|
||||
};
|
||||
|
||||
// 自行车接口
|
||||
// Bike Interface
|
||||
class IBike
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user