> 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.