title: How to deal with class composition when components cannot be accessed from the outside?
body: <p>For example if I say I have three classes <code>A</code>, <code>B</code>, and <code>C</code> where <code>B</code> and <code>C</code> have a composition relation ship with <code>A</code>. That means the life of <code>B</code> and <code>C</code> is handled by <code>A</code>, and also B and C cannot access directly from the outside. </p>
  
  <p>For some reason my <code>DataService</code> class needs to return objects of <code>B</code> and <code>C</code> as It cant return a object of <code>A</code> as <code>B</code> and <code>C</code> cannot be initialized at the same time. (to be able to initialize<code>C</code> you have to initialize<code>B</code> first). </p>
  
  <p>So that I'm returning  <code>DataTables</code> from <code>DataService</code> and then inside the class <code>A</code> those data tables are converted to <code>B</code> / <code>C</code> objects. </p>
  
  <ol>
  <li><p>If <code>B</code> and <code>C</code> objects cannot be initialized at the same time is it valid to say that <code>B</code> and <code>C</code> have a composition relationship with <code>A</code>?</p></li>
  <li><p>If its composition is it must to generate <code>A</code> with <code>B</code> and <code>C</code> inside?</p></li>
  <li><p>What is the proper way to handle this sort of a problem?</p></li>
  </ol>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Following code explains the way I'm doing it now with DataTables.</p>
  
  <p>Example:</p>
  
  <pre><code>class A   
  {  
      private List&lt;B&gt; B;
      private List &lt;C&gt; C;
  
      public A()
      {
          B= new List&lt;B&gt;();
          C= new List&lt;C&gt;();
      }
  
      public List&lt;B&gt; GetB( DataTable dt) 
      {
          // Create a B list from dt
          return B;
      }
  }
  
  
  class Presenter
  {
    private void Show B()
    {
      _View.DataGrid = A.GetB(DataService.GetAListOfB());
    }
  }
  </code></pre>
  
  <p>The actual scenario is I have a class called <code>WageInfo</code> and classes <code>Earning</code> and <code>Deduction</code> having a composition relationship in the design. But for you to generate <code>Deductions</code> first you should Generate <code>earnings</code> and should be saved in a table. Then only you can generate <code>deductions</code> for the <code>earnings</code> to calculate balance wages.</p>
  
  <p>Also note that these contained classes have a one to many relationship with the containing class WageInfo. So actually WageInfo has a <code>List&lt;Earnings&gt;</code> and <code>List&lt;Deduction&gt;</code> </p>
  
  <p>My initial question was, is it ok if my <code>DataService</code> class returns  <code>Deductions</code> / <code>Earnings</code> objects (actually lists) not a <code>WageInfo</code>? </p>
  
  <p>Still not clear? </p>