Am 16.10.2015 um 10:20 schrieb Alik Elzin:
> Hey, for a long time now, I'm not using Java's the *Observable *mechanism
> but rather using my own implementation.
> The reason is that Java's *Observable *mechanism has some pitfalls:
> 1. *Lack of generalization* (*Observer *can receive any object).
Not having generics decouples Observables from the requirements of the
Observers. I.e. it's useful in scenarios where you don't care about
breaking Observers when evolving the Observable (yes such scenarios do
exist).
Of course, today, one could make it Observer<H super G> and
Observable<G> and code the don't-care-about-Observers Observables as
Observable<Object>.
> 2. It's *not concurrent*, meaning behaves slowly when notifying of an event
> (especially if many observers are registered).
Well, *somewhere* you need a list of recipients for the update() call.
If you need to parallelize the update() execution, simply use Observers
that start a separate thread - it's an extra call, but that's likely
negligible compared to the overhead of inter-thread communication. (I
may be wrong; you can still make your point by demonstrating that a
"more concurrent" notification mechanism is faster. Beware that
benchmarking individual elements is really, really hard.)
> 3. It's *cumbersome *with the changed state (It needs to be set manually
> even if a notification is requested).
I did not understand the scenario description.
I.e. what code do you mean how it looks today, how could it be made to
look better?
> 4. It has a *cyclic dependency* between *Observable *and *Observer*.
What cycle do you mean?
Type interdependence? That's normal in Java, and usually not a problem.
You can answer this by explaining what kinds of problems you encounter
from that cyclic dependency. It could be easier to understand, even.
> I'd like to provide another implementation for the observable mechanism and
> thought that guava would be a nice place for it, as guava provides some
> very core complementary functionality and a better observation mechanism is
> down that alley.
Do you have an implementation, or do you plan to build one?
Regards,
Jo