Re: "shared" object
- From: "Silvio Bierman" <sbierman@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 13:25:03 +0100
"Carsten H. Pedersen" <no@xxxxxxx> wrote in message
news:43a6cda0$0$67262$157c6196@xxxxxxxxxxxxxxxxxxxxxxxx
> Hello
>
> I want to create a kind of shared object. I have created a class, Counter,
> which you can then import. Through the Counter class, i would like to have
> access to a shared object.
>
> Lets say that Counter contains only an int, initialised to 1. Each time a
> class importing Counter would do Counter.getNextNumber(), the
> getNextNumber() method would increase the local int, and return the next
> number.
>
> What i want now is when an entirely different class, also importing
> Counter, calls the getNextNumber() method, it does not start out from 1,
> but keeps counting from where another class left off.
>
> I thought of maybe just writing the number to a file, and updating it each
> time getNextNumber() was called. Is there an easier way?
>
>
> - Carsten H. Pedersen
Stay away from static instances/variables, in spite of the earlier
responses. Although this is always a good idea the fact that you want
separate sequences implies that you should go for multiple insatnces of
sequence generators. If you could construct such a generator with an initial
sequence value (as opposed to 1) it would be easy to spawn sequences.
Silvio Bierman
.
- References:
- "shared" object
- From: Carsten H. Pedersen
- "shared" object
- Prev by Date: Re: "shared" object
- Next by Date: web statistic - how?
- Previous by thread: Re: "shared" object
- Next by thread: Desktop Shortcut
- Index(es):
Relevant Pages
|
|