Re: Observer pattern limitations



On Fri, 14 Jul 2006 16:36:25 -0500, Leslie Sanford wrote:

"Dmitry A. Kazakov" wrote in message:
On Fri, 14 Jul 2006 14:29:25 -0500, Leslie Sanford wrote:

Here is an example that can cause a problem:

---------------->

+---+out
| B |--+
+---+ |
+---+ out |in | in+---+out
| A |-------+ +---| D |---->
+---+ |in | +---+
+---+ |
| C |--+
+---+out

So how can this be solved?

[snip]

There exist other solutions as well.

1. In the data-flow language I designed, D is triggered by an
expression @B~@C, which has the semantics: "both time stamps have been
incremented." This kills the race condition between B and C.

2. In synchronous data-flow languages (my is asynchronous) like
Simulink, there is no problem at all, because D(n+1) takes B(n) and
C(n) from the state vector of the previous step.

This second one sounds similar to an another idea I've been toying with.
The components are placed in an array of lists. At each index in the
array, there is a list of components that process the signal at the same
step in the algorithm. So to run the algorithm, you iterate through the
array and iterate through the list at each index, instructing the
components to perform their calculation. In my above example, 'A' would
be at index 0, 'B' and 'C' at index 1, and 'D' at index 2.

So the code for running the algorithm could possibly look like this:

for(int i = 0; i < componentArray.Length; i++)
{
foreach(Component c in componentArray[i])
{
c.Calculate();
}
}

Is this close to what you've described?

Yes, that would be the variant 3. The order is enforced by componentArray.
Items in the elements of componentArray are mutually independent.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: Observer pattern limitations
    ... The components are placed in an array of lists. ... So to run the algorithm, you iterate through the ...
    (comp.object)
  • Re: Cons cell archaic!?
    ... from s-expression or XML or other syntax you keep the bloated array ... For using vectors to emulate lists that ... Allocate 2, move 1 element: ... What do you think of that algorithm? ...
    (comp.lang.lisp)
  • Re: How many bytes per Italian character?
    ... it is a hyrbrid solution between array and list ... Another cool algorithm I did some years ago was to create sparse arrays with constant time ... was to represent parser state tables, where the dimensionality is n*m, for n the number of ... for large lists without thinking too hard about it. ...
    (microsoft.public.vc.mfc)
  • Re: Shuffling a linked list
    ... I have a doubly-linked list of 32 playing cards, ... (For several reasons I'm not using an array, ... Does anybody please have a good algorithm for me? ... You have 2 lists: an input list and an output list. ...
    (comp.programming)