Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 45805 of 46738
Post > Topic >>

Re: Question on Style regarding initialization for inter-working

by =?ISO-8859-1?Q?Marcel_M=FCller?= <news.5.maazl@[EMAIL PROTECTED] > May 8, 2008 at 09:12 AM

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
 




 2 Posts in Topic:
Question on Style regarding initialization for inter-working cla
nomail@[EMAIL PROTECTED]   2008-05-07 22:25:39 
Re: Question on Style regarding initialization for inter-working
=?ISO-8859-1?Q?Marcel_M=F  2008-05-08 09:12:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:59:55 CDT 2008.