Flyweight模式在C ++ [英] Flyweight Pattern in C++
本文介绍了Flyweight模式在C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建flyweight模式时,通常如何存储超浅对象。让我说我创建一架飞机。
When creating a flyweight pattern, how does one usually store superflous objects. Lets say I create an Aircraft.
class Aircraft
{
private:
char make[32];
char model[32];
double cruiseSpeed;
double cruiseAltitude;
double climbRate;
double wingspan;
double fuselageLength;
AircraftType craftType;
public:
Aircraft(void);
Aircraft(AircraftType);
~Aircraft(void);
void setMake(char*);
void setModel(char*);
void setCruiseSpeed(double);
void setCruiseAltitude(double);
void setClimbRate(double);
void setWingSpan(double);
void setFuselageLength(double);
char* getMake();
char* getModel();
double getCruiseSpeed();
double getCruiseAltitude();
double getClimbRate();
double getWingSpan();
double getFuselageLength();
};
还说我在从许多飞机上阅读一个xml数据表,所以我想只是创建一个这些对象并将其余信息存储在某处。我会创建另一个类来管理飞重量信息,然后可能传递一个关键与飞机对象输入到唯一的实例一次?
Lets also say I'm reading in many aircrafts from an xml data sheet, so I want to just create one one these objects and store the rest of the information somewhere. Would I create another class that manages the flyweight information, then maybe pass it a key with the Aircraft object to input into the only instance one at a time? Or would you just bypass putting the information in the object instance at all?
对于这种类型的对象,在不创建多个实例时获得的唯一效率是get和