Connecting Tech Pros Worldwide Help | Site Map

An object to pass around

ikl
Guest
 
Posts: n/a
#1: Jul 22 '05
If an object of a class that is needed in many other class, should it be
passed around into each of them or just create it as a global object so that
all others can access it? Is there any other better ways?

Thanks!


John Harrison
Guest
 
Posts: n/a
#2: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?
>[/color]

You should consider using a Singleton class.

There are many examples of code on the web, you could even search through
the archives of this group.

john


John Harrison
Guest
 
Posts: n/a
#3: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?
>[/color]

You should consider using a Singleton class.

There are many examples of code on the web, you could even search through
the archives of this group.

john


jeffc
Guest
 
Posts: n/a
#4: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?[/color]

Either can work - "it depends".


jeffc
Guest
 
Posts: n/a
#5: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?[/color]

Either can work - "it depends".


Nick Hounsome
Guest
 
Posts: n/a
#6: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?[/color]

It's always best to pass it around as this is the most flexible and reusable
method.
Most of us are too lazy though so we just use a singleton pattern about
which there is a thread
started every few days!


Nick Hounsome
Guest
 
Posts: n/a
#7: Jul 22 '05

re: An object to pass around



"ikl" <ikl72@dsp.com> wrote in message
news:DDPcc.30076$vo5.952840@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> If an object of a class that is needed in many other class, should it be
> passed around into each of them or just create it as a global object so[/color]
that[color=blue]
> all others can access it? Is there any other better ways?[/color]

It's always best to pass it around as this is the most flexible and reusable
method.
Most of us are too lazy though so we just use a singleton pattern about
which there is a thread
started every few days!


Closed Thread