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();
};
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?
For this type of object, would the only efficiency gained in not creating multiple instance be the get and sets?
Look at the boost flyweight implementation. After you do, just use boost flyweight.
If you don't want to use boost, use boost in such case.