An object to pass around

I

ikl

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!
 
J

John Harrison

ikl said:
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?

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
 
J

jeffc

ikl said:
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?

Either can work - "it depends".
 
N

Nick Hounsome

ikl said:
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?

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top