Architecture design with MyBatis mappers

Posted by Wolf on Programmers See other posts from Programmers or by Wolf
Published on 2013-11-07T11:41:36Z Indexed on 2013/11/07 16:11 UTC
Read the original article Hit count: 412

Filed under:
|
|

I am creating rest web service for providing data. I am using Spring MVC for handling rest requests, and MyBatis for data access. Application should be designed in the way that it should be easy to change the data access implementation (for example to hibernate or something else) and it has to be fast (so I am trying to avoid unnecessary overcomplication of design).

Now my question is about the general design of layers. I would normally use DAO interface and then different implementations for different data access strategies, but MyBatis uses interfaces to access the data. So I can think of 2 possible models but I am not sure which one is better or if there is any other nice way:

  1. Controller layer - uses Service layer interfaces

    • services are then implemented for each data access stretegy - for example for mybatis:

    • service implementation uses Mapper classes to access data and do whatever it needs to do with them and sends them to controller layer

  2. Controller layer - uses Service layer - service layer uses DAO interfaces

    • DAOs are then implemented for each data access strategy - for example for mybatis:

    • DAO class uses mapper interface to access data and sends them to service layer, service layer then do whatever it needs to do with them and sends them to controller layer

I prefer the first strategy as it seems to be less complicated, but then I would have to write all of the service code for another data access again. What do you think? Thank You

© Programmers or respective owner

Related posts about java

Related posts about design