title: How to implement the Business Logic layer and the Repository Layer with Java Spring Boot?
body: <p>I am trying to create the Business Logic (Service) and the Repository (Data access) Layer for my application. I want to do it correctly but I am not an expert.</p>
  
  <p>For the moment, for the Repository layer, I've created an interface <strong>IMainDao</strong> that extends <strong>JpaRepository</strong>:</p>
  
  <pre><code>import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  @Repository
  public interface IMainDao extends JpaRepository&lt;Object, Integer&gt;{
  }
  </code></pre>
  
  <p>So all my repositories interfaces can extend the IMainDao:</p>
  
  <pre><code>import org.springframework.stereotype.Repository;
  
  @Repository
  public interface IUserDao extends IMainDao{
  
  }
  </code></pre>
  
  <p>I also created the Business Logic layer. An interface <strong>IMainService</strong>:</p>
  
  <pre><code>import java.util.List;
  import org.springframework.stereotype.Service;
  
  @Service
  public interface IMainService {
  
      Object getById(int id);
      List&lt;Object&gt; getAll();
      Object create(Object o);
      Object update(Object o);
      void delete(int id);
  }
  </code></pre>
  
  <p>The implementation of this interface <strong>MainService</strong></p>
  
  <pre><code>@Service
  public class MainService implements IMainService{
  
      @Autowired
      private IMainDao mainDao;
  
      @Override
      public Object getById(int id) {
          return mainDao.findById(id);
      }
  
      @Override
      public List&lt;Object&gt; getAll() {
          return mainDao.findAll();
      }
  
      @Override
      public Object create(Object o) {       
          Object obj = mainDao.save(o);     
          return obj;
      }
  
  //Other methods...
  </code></pre>
  
  <p>And the other interfaces like <strong>IUserService</strong> that extend <strong>IMainService</strong>:</p>
  
  <pre><code>import org.springframework.stereotype.Service;
  
  @Service
  public interface IUserService extends IMainService{
  
  }
  </code></pre>
  
  <p>With their implementations:</p>
  
  <pre><code>public abstract class UserService implements IUserService{
  
  }
  </code></pre>
  
  <p>Am I doing it correctly? If no, what do you recommend to me and where can I optimize?</p>
  
  <p>Thanks!</p>