#pragma once
#include "iostream"
class Implementor
{
public:
virtual void operatorImp() = 0;
};
class ImplementorA : public Implementor
{
public:
virtual void operatorImp() {
std::cout << __FUNCTION__ << ": A" <<std::endl;
}
};
class ImplementorB : public Implementor
{
public:
virtual void operatorImp() {
std::cout << __FUNCTION__ << " : B" << std::endl;
}
};
class ImpFactory
{
public:
static ImpFactory* getInstance() {
if (imp_factory == NULL)
{
imp_factory = new ImpFactory();
std::cout << __FUNCTION__ << std::endl;
}
return imp_factory;
}
static Implementor* makeImp(int type) {
std::cout << __FUNCTION__ << std::endl;
if (type == 1)
{
return new ImplementorA();
}
else if(type ==
设计模式之桥接与工厂模式
最新推荐文章于 2022-05-29 22:13:28 发布
本文探讨了设计模式中的桥接模式和工厂模式。通过实例展示了如何在实际编程中应用log4cpp库的工厂模式进行日志处理。
摘要由CSDN通过智能技术生成