flyweightfactory.cpp

来自「23中设计模式大家都应该知道吧」· C++ 代码 · 共 31 行

CPP
31
字号
//FlyweightFactory.cpp
#include "FlyweightFactory.h" 

#include <iostream> 
#include <string> 
#include <cassert> 
using namespace std;

FlyweightFactory::FlyweightFactory() 
{
}

FlyweightFactory::~FlyweightFactory() 
{
}

Flyweight* FlyweightFactory::GetFlyweight(const string& key) 
{ 
	vector<Flyweight*>::iterator it = _fly.begin();
	for (; it != _fly.end();it++) 
	{ //找到了,就一起用,^_^ 
		if ((*it)->GetIntrinsicState() == key) 
		{ 
			cout<<"already created by users...."<<endl;
			return *it; 
		} 
	}
	Flyweight* fn = new ConcreteFlyweight(key);
	_fly.push_back(fn);
	return fn; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?