Was just thinking about this question while trying to figure out some code written by our previous developer. Trying to trace out how control of the program was happening reminded me of the bad old days of BASIC, where it was hardly ever obvious the execution path of a program. Is this more a symptom of event abuse, or is there a structual problem with the observer pattern?
Was just thinking about this question while trying to figure out some code written
Share
Like any technology, events can be used incorrectly and abused. However, since you didn’t give any examples of your problem, it’s virtually impossible for us to tell what you’re talking about.
In general, no. Events are not the OO equivalent of
GOTO, nor are they typically a problem. Nor is there any structural problem with the observer pattern that I’m aware of. But abuse can happen with anything.GOTO’s are bad for a lot of reasons, but one of the biggest ones is that it is a transfer of program flow, not merely a subroutine execution. When you use a goto, program execution does not return to the point after your goto call when it’s done (or after it’s been initiated in the case of an asynchronous event). Program flow is transfered permanently to the new execution point. What’s worse, is that it can transfer execution to anywhere, including inside other control structures or other functions.
Events simply do not have these characteristics, and are little more than function pointers with object awareness and a publish/subscribe capability. (ok, there’s a lot more than that, but this is their basic usage)