Hello Richard,
thanks for sharing your ideas and the detailed description how a
completely event-driven system works.
Richard Cornford wrote:[color=blue]
> Awkwardness is going to be largely a matter of perception. Procedural
> code doesn't lend itself to asynchronous operation but OO code shouldn't
> be such a problem. In OO the 'state' should be a quality of the objects
> not the stack.[/color]
Yes, it's the feeling that makes one prefer a certain design. I would
not rule out procedural code for async operations. E.g. I imaging that
implementing a network protocol using a statemachine is an appropriate
approach. In OO code you would break up the case/switch statements and
"spread them around", delegate it to objects and their methods. Now the
objects keep their own state (and implement a statemachine). Is this
advantageous, I don't know.
Maybe it's just because I have a background in procedural programming.
So designing a completely event-driven system, where objects interact
sending async messages seems counter-intuitive because it lacks a main
flow of control.
I found the following example helpful:
In procedural programming you often have the control flow in a main
routine that calls other components only to do lower-level tasks. The
main routine can be long and complex but it gives the whole thing a
logical structure.
In an event-driven program you don't have that control flow in the main
routine. The main routine sends of messages and mainly consists of event
handlers. Not the main routine but the objects are now "in charge" and
not only sequentially, but also concurrently as messages and events may
happen any time. So the logical structure of the program is scattered
around and interactions among objects may be hard to understand.
Additionally, the use of ordinary linguistic constructs like loops,
stack allocated variables, ... is limited as these disappear accross
callbacks/messages.
Well, maybe one just has to get used to it :-) I'd like to see a real
good example of an event-driven system with object interaction through
messages implemented using Javascript.
[color=blue][color=green]
>>See the sequence diagram in [2].[/color]
>
> I see no sequence diagram.[/color]
Because there is none :-) I referred to the wrong footnote. See here for
the sequence diagramm instead:
<427113ea$0$10510$9b4e6d93@newsread4.arcor-online.net>
http://groups.google.de/group/de.com...dba787abae68d4
Cheers
Daniel