Name of Parameterize Constructor pattern alternative

  c++, design-patterns

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{
public:
  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 {
public:
  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{
public:
  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.

Source: Windows Questions C++

LEAVE A COMMENT