Hi,
nomail@[EMAIL PROTECTED]
schrieb:
> The question is, should the Environment class hold an instance of
> the Output class, or just a pointer?
use the pointer. You will never be able to deal with different outputs
otherwise.
> If it had an instance, then I would need to create new constructors
> in the Environment class in order to pass the string. This seems
> kinda clunky, as now I have modified the environment in order to
> appease some other class.
Exactly.
> It does have the advantage of
> initialization of all classes at once.
> The alternative would be for the Environment class to use a pointer to
> the Output class, but the Output class would have to initialized
> outside the environment class, and then the pointer set. From a
> program perspective, this just takes a couple of extra steps,
> but I need to make sure that the pointer is always set.
Not neccessarily, see below.
> I may have already answered my question if I want inheritance
> for the Output class (the pointer method would work better), but
Exactly.
> I was wondering in terms of style if there is a better
> style/method/whatever.
Use a factory for the output class. The environment may invoke this
factory to get an apropriate output. The factory should know how to
initialize the output before it is invoked. So it takes no parameters
from the Environment.
This makes the initialization of an environment instance one line. Of
course you have to configure the factory first, but only once.
Marcel


|