title: Can I call this an implementation of the Composite Pattern
body: <p>I have this design which I self-proclaim to be Composite Pattern, though I'm not entirely sure about that. So I'm aksing for your statement on this.</p>
  <p>This is the interface which collectively describes all of them</p>
  <pre><code>public interface DomainResourceBuilder&lt;T extends DomainResource&gt; {
  
      T buildInsertion(T persistence, EntityManager entityManager) throws Exception;
  
      T buildUpdate(T model, T persistence, EntityManager entityManger);
  
      &lt;E extends T&gt; DomainResourceBuilder&lt;E&gt; and(DomainResourceBuilder&lt;E&gt; next);
  
  }
  </code></pre>
  <p>This one describes <code>DomainResourceBuilder</code> as a pair</p>
  <pre><code>public abstract class AbstractDomainResourceBuilder&lt;D extends 
      DomainResource&gt; implements DomainResourceBuilder&lt;D&gt; {
  
      @Override
      public &lt;E extends D&gt; DomainResourceBuilder&lt;E&gt; 
          and(DomainResourceBuilder&lt;E&gt; next) {
          return new CompositeDomainResourceBuilder&lt;&gt;(this, next);
      }
  
      private class CompositeDomainResourceBuilder&lt;T extends D&gt; 
          extends AbstractDomainResourceBuilder&lt;T&gt; {
  
          private final DomainResourceBuilder&lt;D&gt; parentBuilder;
          private final DomainResourceBuilder&lt;T&gt; childBuilder;
  
          public 
             CompositeDomainResourceBuilder(DomainResourceBuilder&lt;D&gt; 
             parentBuilder,
             DomainResourceBuilder&lt;T&gt; childBuilder) {
              super();
              this.parentBuilder = parentBuilder;
              this.childBuilder = childBuilder;
          }
  
          @SuppressWarnings(&quot;unchecked&quot;)
          @Override
          public T buildInsertion(T model, EntityManager 
              entityManager) throws Exception {
              return childBuilder.buildInsertion((T) 
              parentBuilder.buildInsertion(model, entityManager), 
                  entityManager);
          }
  
          @SuppressWarnings(&quot;unchecked&quot;)
          @Override
          public T buildUpdate(T model, T persistence, 
              EntityManager entityManger) {
              return childBuilder.buildUpdate(model, (T) 
                  parentBuilder.buildUpdate(model, persistence, 
                      entityManger), entityManger);
          }
      }
  }
  </code></pre>
  <p>Concrete class plays the <code>Leaf</code> role</p>
  <pre><code>public class CustomerBuilder extends AbstractDomainResourceBuilder&lt;Customer&gt; {
  
      @Override
      public
          Customer buildInsertion(Customer persistence, EntityManager entityManager) throws Exception {
          return persistence;
      }
  
      @Override
      public
          Customer buildUpdate(Customer model, Customer persistence, EntityManager entityManger) {
          return persistence;
      }
  
  }
  </code></pre>
  <p>Can I call this a Composite Pattern?</p>
  <p>This is how I use it. Assumming I have the following hierarchy.</p>
  <pre><code>AbstractEntity
  |___User
      |___Customer
  </code></pre>
  <p>Now I want to implement different logics on each class, so with the design I'll create specific logic for those class and then ultimately compose them into one, which is still one of their kind. Something like this.</p>
  <pre><code>// group of objects
  DomainResourceBuilder&lt;AbstractEntity&gt; abstractEntityBuilder = new AbstractEntityBuilder&lt;&gt;();
  DomainResourceBuilder&lt;User&gt; userBuilder = new UserBuilder&lt;&gt;();
  DomainResourceBuilder&lt;Customer&gt; customerBuilder = new CustomerBuilder&lt;&gt;();
  // treat them as a whole (unify them all)
  DomainResourceBuilder&lt;Customer&gt; compositeCustomerBuilder = 
      abstractEntityBuilder
      .and(userBuilder)
      .and(customerBuilder);
  </code></pre>