Coroutine's Communication

DavidL Davidl at 126.com
Tue Apr 29 19:00:32 PDT 2008


terranium Wrote:

> davidl Wrote:
> > The trick here is that routines are still routines, and you defaultly get  
> > their local vars consisting an object.
> 
> Function's local variables don't comprise and object. func1 obvously wants a state object, so should accept it using normal parameter declaration. If you want to pass func1 various state objects you can declare func1 as a templated function.

OO not always bring you the good thing. Somtimes they fail in the abstraction.

Consider:
void provider()
{
   // I need to sum some field of the record for some specific consumers, but not all consumers need this sum !
   my_rec_struct rec;
   open_table();
   bool done=false
   while (fetch_first_record(&rec)!=0)
  {
     yield consumer(get_current_scope);
  }
  done = true;
}

void consumer(provider_scope scope)
{
   int sum;
   while(!scope.done)
   {
       sum += provider_scope.rec.amount;
       yield provider();
   }
}

in this specific consumer we need the sum result. while not *every* consumer needs this, some consumer just need to iterate over the data, they do not necessarily need the sum of amount. How do you solve in your oo state object??
It's ridiculous to do it in OOP, and it's definitely unsuitable and stupid.



More information about the Digitalmars-d mailing list