I'm not sure how to ask, or title this question effectively (so reviewers, please have at it)
Given that a default constructor looks akin to:
class Foo{
Foo();
};
when the need arises to configure this instantiation, a typical approach often referred to as the "Parameterize Constructor" pattern might look like:
class Foo {
Foo(int param1, double param2);
};
There exists a common alternative for which I do not know its name -- Essentially the signature remains default, but the body of the constructor method calls out to one or more data sources to configure itself. Such as:
class Foo{
Foo();
};
Foo::Foo() {
int param1 = parseFileOnDisk(...);
...
double param2 = queryConfigurationDatabase(...);
}
All qualitative judgment aside, is there a name for the latter approach? I have encountered this pattern in multiple contexts, but never quite know how to refer to it.
Aucun commentaire:
Enregistrer un commentaire