title: (Entity-Control-Boundary pattern) -> How to deal with two entities?
body: <h2>Premise</h2>
  <p>I've recently read/watched a lot of articles/videos by Java Champion Adam Bien, where he advocates the usage of the <em>ancient</em> but <em>renewed</em> <strong><a href="http://www.adam-bien.com/roller/abien/entry/bureaucratic_design_with_java_ee" rel="noreferrer">Entity - Control - Boundary</a> Design Pattern</strong> JAVA EE &gt;= 6.</p>
  <p>Leveraging on CDI, EJB 3.1, JPA 2 and other JAVA EE 6 features, this pattern should help creating more business-oriented <em>components</em>, easier to unit-test, and with a higher separation of concerns based on the responsibilities.</p>
  <p>Since I'm using all of the features listed above, and this pattern sounds very interesting, I'm scouting it to see if ECB can fit my next project requirements.</p>
  <br/>
  <h2>What I've got so far</h2>
  <p>In ECB each logical entity is split in three pieces (please correct me if I'm wrong):</p>
  <ul>
  <li><p>a <strong>Boundary</strong>, a sort of powerful Façade, the only Class accessible from <em>outside</em>. And for <em>outside</em> (if I got it right), we mean both <em>outside the application</em>, eg. a remote client, AND <em>outside of the component package</em>, eg. another part of my application;</p>
  </li>
  <li><p>a(n optional) <strong>Controller</strong>, responsible for some kind of operations (for example, the validation of the Entity);</p>
  </li>
  <li><p>an <strong>Entity</strong>, that can be a pure JPA Entity, but can also contain some <em>decoration / validation / (minimal) business</em> logic inside.</p>
  </li>
  </ul>
  <p>For example, consider having two different entities (<code>Orange</code> and <code>Apple</code>), a class to do CRUD on them (<code>FruitsManager</code>) and a class to perform some controls over them (<code>FruitsQualityChecker</code>).</p>
  <p>Until yesterday, It would have been something like (<strong>OLD WAY</strong>):</p>
  <blockquote>
  <pre class="lang-java prettyprint-override"><code>com.foo.bar.business.FruitsService        /* CRUD    */
  com.foo.bar.business.FruitsQualityChecker /* CONTROL */
  com.foo.bar.model.Orange                  /* ENTITY  */
  com.foo.bar.model.Apple                   /* ENTITY  */
  </code></pre>
  </blockquote>
  <p>while with ECB I would have (<strong>NEW WAY</strong>):</p>
  <blockquote>
  <pre class="lang-java prettyprint-override"><code>com.foo.bar.business.oranges.boundary.Oranges       /* CRUD    */ 
  com.foo.bar.business.oranges.control.QualityChecker /* CONTROL */
  com.foo.bar.business.oranges.entity.Orange          /* ENTITY  */
  
  com.foo.bar.business.apples.boundary.Apples         /* CRUD    */
  com.foo.bar.business.apples.control.QualityChecker  /* CONTROL */
  com.foo.bar.business.apples.entity.Apple            /* ENTITY  */
  </code></pre>
  </blockquote>
  <p>Then I can CRUD and research each entity singularly, eg. with</p>
  <pre class="lang-java prettyprint-override"><code>Oranges.findOrangesByPrice(min, max);
  </code></pre>
  <br/>
  <h2>Main Question</h2>
  <p><em><strong>How should I handle a cross-component research, like for example</strong></em> <code>findFruitsByPrice(min,max)</code><em><strong>?</strong></em></p>
  <p>Should I call both <code>findOrangesByPrice</code> and <code>findApplesByPrice</code> and summing the results? From which Class, packaged where?
  And what if I have a search page with many criteria, that must cross 50 entities? Running 50 times the search method of each entity, and then perform the interpolation, sounds like a very ugly way with a huge impact on performance. I guess I still need a central point somewhere to perform this kind of thing. Should it be another component, called e.g. <code>Searches</code>, that in its Boundary calls the other boundaries? This point is obscure to me ATM.</p>
  <br/>
  <h2>Side Question</h2>
  <p><em><strong>Does it make sense to use ECB with an action-based framework? Or is this pattern relegated to component-based frameworks?</strong></em></p>
  <p>I'm using Struts2, that is an MVC action-based framework, and I'm quite unfamiliar with JSF2 (JAVA EE 6 standard, and used in most of Adam Bien's showcases) that is an MVC component-based framework;</p>
  <p>Apart from the additional effort of thinking the architecture <em>&quot;the component way&quot;</em>, is there something preventing me to use ECB on the <strong>business</strong> layer?</p>
  <p>Since the majority of the boundaries in Adam Bien's examples are REST services (generally more a replacement of Struts2 Actions than a <em>&quot;new gear in the chain&quot;</em>), this makes me doubt it could be <em>completely</em> suitable for a Struts2 ecosystem.</p>
  <p>Say yours. Please.</p>