mirror of
https://github.com/huihut/interview.git
synced 2025-12-18 21:14:38 +03:00
添加设计模式及例子,包括:单例、抽象工厂、适配器、桥接、观察者模式
This commit is contained in:
46
DesignPattern/AbstractFactoryPattern/FactoryMain.cpp
Normal file
46
DesignPattern/AbstractFactoryPattern/FactoryMain.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by xiemenghui on 2018/7/20.
|
||||
//
|
||||
|
||||
#include "Factory.h"
|
||||
#include "product.h"
|
||||
#include "FactoryMain.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
void FactoryMain()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
Factory * pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::BENZ_FACTORY);
|
||||
ICar * pCar = pFactory->CreateCar();
|
||||
IBike * pBike = pFactory->CreateBike();
|
||||
|
||||
cout << "Benz factory - Car: " << pCar->Name() << endl;
|
||||
cout << "Benz factory - Bike: " << pBike->Name() << endl;
|
||||
|
||||
SAFE_DELETE(pCar);
|
||||
SAFE_DELETE(pBike);
|
||||
SAFE_DELETE(pFactory);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::BMW_FACTORY);
|
||||
pCar = pFactory->CreateCar();
|
||||
pBike = pFactory->CreateBike();
|
||||
cout << "Bmw factory - Car: " << pCar->Name() << endl;
|
||||
cout << "Bmw factory - Bike: " << pBike->Name() << endl;
|
||||
|
||||
SAFE_DELETE(pCar);
|
||||
SAFE_DELETE(pBike);
|
||||
SAFE_DELETE(pFactory);
|
||||
|
||||
// <20>µ<EFBFBD>
|
||||
pFactory = Factory::CreateFactory(Factory::FACTORY_TYPE::AUDI_FACTORY);
|
||||
pCar = pFactory->CreateCar();
|
||||
pBike = pFactory->CreateBike();
|
||||
cout << "Audi factory - Car: " << pCar->Name() << endl;
|
||||
cout << "Audi factory - Bike: " << pBike->Name() << endl;
|
||||
|
||||
SAFE_DELETE(pCar);
|
||||
SAFE_DELETE(pBike);
|
||||
SAFE_DELETE(pFactory);
|
||||
}
|
||||
Reference in New Issue
Block a user