title: Pros and Cons of Inversion of Control
body: <p>Suppose I have a stream of [acme] objects that I want to expose via an API.  I have two choices, callbacks and iterators.</p>
  
  <h1>API #1: Callbacks</h1>
  
  <pre><code>// API #1
  // This function takes a user-defined callback 
  // and invokes it for each object in the stream.
  template&lt;typename CallbackFunctor&gt;
  void ProcessAcmeStream(CallbackFunctor &amp;callback);
  </code></pre>
  
  <h1>API #2: Iterators</h1>
  
  <pre><code>// API #2
  // Provides the iterator class AcmeStreamIterator.
  AcmeStreamIterator my_stream_begin = AcmeStreamIterator::begin();
  AcmeStreamIterator my_stream_end   = AcmeStreamIterator::end();
  </code></pre>
  
  <p>API #1 takes the control flow of the program from the user's hand and will not return until the entire stream is consumed (forgetting exceptions for the moment).</p>
  
  <p>API #2 retains the control flow in the user's hand, allowing the user to move forward the stream on his own.</p>
  
  <p>API #1 feels more <em>higher level</em>, allowing the users to jump to the <em>business logic</em> (the callback functor) right away.  On the other hand, API #2 feels more flexible, allowing the users lower-level of control.</p>
  
  <p>From a design perspective, which one should I go with?  Are there more pros and cons that I have not seen yet?  What are some support/maintenance issues down the future?</p>