Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Newbie Scope question

Thread view: 
Andreas Nicoletti - 31 Mar 2005 02:02 GMT
hi,

I have multiple objects of the same class that (Dice d6, d10, ...)
I want to make available throughout a package (like a global).

How do I do that?
iamfractal@hotmail.com - 31 Mar 2005 08:41 GMT
> hi,
>
> I have multiple objects of the same class that (Dice d6, d10, ...)
> I want to make available throughout a package (like a global).
>
> How do I do that?

Hi, Andreas!

You must either:
1) Pass them, perhaps as a List, as method parameters to all clients
in the package that require access to them.

2) Store the objects in a central repository within the package, and
have all the clients access the repository. This, of course, may give
rise to the circular, "How do the clients access the repository?"
Well, you can either do (1), and pass the repository to all clients;
or make the repository a singleton, exposing the static mathod
getInstance(); this will return an interface with set(Dice dice) to
store dice in the repository, and a getDice() which will return,
perhaps, a List of all dice stored.

Note that both solutions will require attention to timing: the clients
mustn't request the dice until the dice are created (or else they must
cater for that eventuality).

[Also note (the ghost of my old English teacher has just drifted
wailing into the door) that, "Dice," is the plural of, "Die;" so may
those objects are Die d6, d10, ... B)]

.ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
Andreas Nicoletti - 01 Apr 2005 01:48 GMT
> 2) Store the objects in a central repository within the package, and
> have all the clients access the repository. This, of course, may give
[quoted text clipped - 4 lines]
> store dice in the repository, and a getDice() which will return,
> perhaps, a List of all dice stored.

Creating a central repository sounds like what I want. I will begin
reading about 'singletons', and 'getInstance()'. Is there any other
topics I should read about that would help here?

> [Also note (the ghost of my old English teacher has just drifted
> wailing into the door) that, "Dice," is the plural of, "Die;" so may
> those objects are Die d6, d10, ... B)]

You are quite correct I shall correct my naming scheme accordingly.

Thank you!

Andreas
HalcyonWild - 01 Apr 2005 12:50 GMT
> > hi,
> >
[quoted text clipped - 29 lines]
>
> www.EdmundKirwan.com - Home of The Fractal Class Composition.

What about using default access modifier.. that is package. I guess by
default, if you do not mark your fields or methods as
private/public/protected, it takes it as package.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.