title: Composite design pattern: how to pass results from one component into another?
body: <p>I have the following code:</p>
  
  <pre><code>interface IService
  {
      void Execute();
  }
  
  class ServiceA : IService
  {
      public void Execute() { ... }
  }
  
  class ServiceB : IService
  {
      public void Execute() { ... }
  }
  
  class ServiceComposite : IService
  {
      List&lt;IService&gt; _services = new List&lt;IService&gt;();
  
      public ServiceComposite()
      {
          _services.Add(new ServiceA());
          _services.Add(new ServiceB());
      }
  
      public void Execute()
      {
          foreach (IService service in _services)
          {
              service.Execute();
          }
      }
  }
  </code></pre>
  
  <p>The problem is that ServiceB depends on some results from ServiceA. My idea is to create container class for storing the results, then inject it into both ServiceA and ServiceB:</p>
  
  <pre><code>class ServiceResults
  {
      public string SomeProperty {get; set;}
  }
  
  public ServiceComposite()
  {
      ServiceResults result = new ServiceResults();
      _services.Add(new ServiceA(result));
      _services.Add(new ServiceB(result));
  }
  </code></pre>
  
  <p>I am wondering if it is the best possible way to solve the problem. Maybe it breaks some principles or rules of which I don't know, or is simply "code smell". What are the better ways to do this?</p>