OOP question....proper way to have 2 objects reference each
bofh at stremler.net
Tue Nov 24 16:40:37 PST 2009
begin quoting chris at seberino.org as of Tue, Nov 24, 2009 at 01:49:44PM -0800:
> On Tue, Nov 24, 2009 at 07:22:53AM +0000, SJS wrote:
> > Some folks use a "service" like JNDI, and each object registers itself with
> > the JNDI server, and when objects need to find it, they ask the JNDI server.
> > Almost always I end up wrapping the JNDI server acess into a helper class
> > that I pass in to all objects, at which point I might as well write a
> > helper class:
> There is a brilliant way to do this with event programming that seems to do
> the same thing you are suggesting with JNDI.
> You can make up your own "events" and register your event handlers to
> your custom "events".
> Now if you can cause that "event" to happen with a certain function call,
> then *any* object can invoke a registered method (handler) on any object by
> firing that "event" off!!
...that's the whole point of an event system, isn't it?
> Encapsulation is preserved and everyone wins!
Well, at a cost of greater complexity.
Everything's a tradeoff. ALWAYS look for the downside, so you can ask
"is this worth the cost in this situation?"
If there's no downside, someone is blowing smoke.
More information about the KPLUG-List