How to handle a shared object reference?
From: Ken (kk_oop_at_yahoo.com)
Date: 07/31/04
- Next message: Frank: "Re: TCP server does not detect the client network failure"
- Previous message: Roedy Green: "Re: Your Guru Paul Graham is getting trashed on Slashdot."
- Next in thread: VisionSet: "Re: How to handle a shared object reference?"
- Reply: VisionSet: "Re: How to handle a shared object reference?"
- Reply: xarax: "Re: How to handle a shared object reference?"
- Reply: kk_oop
: "Re: How to handle a shared object reference?" - Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jul 2004 18:48:43 -0700
Hi. I'm doing a design using Java that has two hierarchies of
classes. Each hierarchy is defined by containment. So it's something
like:
class A contains an instance of B;
class B contains an instance of C;
class C contains an instance of D;
class A contains an instance of E;
class E contains an instance of F;
class F contains an instance of G;
So both hierarchies start with class A.
Using this example, classes D and G (the classes at the bottom of
these hierarchies) both use the same instance of another class. We'll
call that class SharedClass. D creates, writes to and reads from
SharedClass. G reads from and writes to the same instance of
SharedClass. However, each instance pair of D and G will share a
different instance of SharedClass. In other words, SharedClass is not
a Singleton.
My question is this: How do I make a SharedClass instance available
to both D and G? At first I was going to have A create the
SharedClass instance and have it work its way down to D through the
constructor parameters of B and C, and likewise get it to G via E and
F. However, that would let A, B, C, E and F touch this SharedClass
instance when they don't really need it.
Could someone recommend an alternative approach?
Thanks!
Ken
- Next message: Frank: "Re: TCP server does not detect the client network failure"
- Previous message: Roedy Green: "Re: Your Guru Paul Graham is getting trashed on Slashdot."
- Next in thread: VisionSet: "Re: How to handle a shared object reference?"
- Reply: VisionSet: "Re: How to handle a shared object reference?"
- Reply: xarax: "Re: How to handle a shared object reference?"
- Reply: kk_oop
: "Re: How to handle a shared object reference?" - Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|