Good post by John Carter to the pragprog@yahoogroups.com
Let me relate a few war stories...
Once I had a very very complex problem to solve.
I had not the foggiest notion in which order to compute what.
So I took the cowards way and hooked in the Observer all over the place
so I didn't have to think in what order to do it.
It was very slow and buggy and I was no closer to understanding in the
problem than before. It did work occasionally though.
I put in enough logging to see what order it did things in (when it
worked). After glaring at that for an hour I saw the pattern, recoded
it as a couple of tight while loops.
Result...
Very fast, very understandable, easily maintained, no bugs and no observers.
Story two...
Once I took over the maintenance of some code that had several
observer pattern instances scattered around it.
It was fragile, buggy, and erratic.
After much loss of hair and many hours of poring over log traces I
figured it out.
There were complex loop paths through several observers. No mere
mortal could really understand what would happen if object X updated,
since the possible impacts and possible variants of paths were almost
limitless and depended crucially on the order of registration of
observers.
After a brief killing spree amongst the instances of the observer
pattern the code was still buggy, but at least no longer fragile and
erratic...
|