Sometimes I initialize my classes by passing to it a POD (Plain Old Data). This reduces the number of parameters I have to pass to the function (whether it is the constructor or an init function), it allows me to not care about the order in which they are declared, and to change the number and nature of parameters without having to change method signatures.
I find it handy.
Here is a small example:
class Manager
{
public:
struct Configuration
: mDataVectorSize( 20 )
, mShouldOutputDebug( false )
{
int mDataVectorSize;
bool mShouldOutputDebug;
};
Manager(const Configuration& aConfiguration);
void serviceA();
void serviceB();
private:
Configuration mConfiguration;
std::vector<int> mData;
};
With the usage:
Manager::Configuration config;
config.mDataVectorSize = 30;
Manager manager( config );
manager.serviceA();
What is the name of this pattern, if it’s even a pattern? I thought that it was called Flyweight, but reading the description on Wikipedia, it doesn’t exactly match what’s in here.