title: Batch and business layer communication
body: <p>I'm designing a batch application using Spring batch where I have the following architecture (layers):</p>
  
  <ul>
  <li>A top module where I put all the spring batch code (reading the file, processing and writing). This top module is specific to a certain format of the file. So, I may have in the future an new parallel module that would be able to read/process/write a new format. Independently of the format, each line of a file corresponds to a certain operation to execute. For example, each line may represent the operation "Add line item X to order Y". So, for each line, after finishing to read and process it, I use a custom ItemWriter that calls the required operation of the layer immediately below.</li>
  <li>A business logic layer that would implement the different batch operations. Each one of these operations is implemented using the domain layer objects. For example, the "Add line ite; X to order Y" operation would be implemented by retrieving the order using the OrderRepository and then by calling the addLineItem method of the order.</li>
  <li>A domain layer where I have all my domain objects. Following the previous example, I have the Order and LineItem entities.</li>
  </ul>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is there a best practice (maybe a specific design pattern) to use for the interface between the top modules and the business logic layer?</li>
  <li>Let's assume that each file contains lines for only one order. The naive approach for writing each line would be to call one batch operation per line. In this case, for each line, a call to the OrderRepository is done to retrieve the order and then the order is saved. I'm thinking about another approach where lines are written by chunk (as we do with Spring batch). The argument that the write operation takes has the type List. Following this second approach, I would need to pass to the business operation the data it needs to add the chunk to the concerned order. Which form to use to pass the information between the top module and the business logic layer?</li>
  </ul>
  
  <p>Thanks</p>