title: Spring DI : Aggregation or Composition
body: <p><strong>Aggregation:</strong> If two objects have there own life cycle and not tightly coupled with each other(can exists independently).</p>
  
  <pre><code>Class A {
      B b;
  } 
  </code></pre>
  
  <p>The default value for <code>b</code> will be <code>null</code> and <code>A's</code> object can exists if there is no instance injected in A.</p>
  
  <p><strong>Composition:</strong> if two objects are tightly coupled and one can not exists without second.</p>
  
  <pre><code>Class A{
     B b;
     A(B b){
        this.b = b;
      }
  }
  </code></pre>
  
  <p><strong>Spring DI:</strong> In spring if we are using <code>@Autowired</code> annotation over a member then this member is required before instantiation of object.</p>
  
  <pre><code>Class A{
    @Autowired  */ now this member is required before creating of object of A.
    B b;
  }
  </code></pre>
  
  <p><strong>Query:</strong> So from the above facts we can think <code>Spring DI</code> as a composition here .I am asking this question because in a interview I had a discussion over it and as per the interviewer <code>Spring</code> is using <code>Aggregation</code> here. 
  Could any one please clarify if I am missing or not getting some thing here.</p>