Women in Technology

Hear us Roar



Article:
  iBatis DAO
Subject:   Why extend Dao?
Date:   2005-09-30 07:06:37
From:   adamkrieg
Response to: Why extend Dao?

Well, ideally, you'd like to have your interfaces be unconcerned with how the thing is actually implemented behind the scenes. Whether we're actually saving the thing to a Database by JDBC, to a database by iBatis, or to an xml file shouldn't be refected in the interface. You have introduced a tiny little artifact of the implementation in the fact that your interface has to extend Dao.


I can see times you might want to package your interfaces in a separate package than the actual implementation along with the business objects that you are saving, reading, etc. You'd like that package to be as dependency free as possible. For example, a Client/Server type app over RMI might have a Client package, a Common package and a Server package, with the Dao interface in the Common package to be shared by both the client and the server package. Now, you've introduced a dependency on the iBatis Dao interface which requires us to have the iBatis jar in the client's classpath, when the client could care less that we're using iBatis behind the scenes on the server.


I'm not trolling here, just trying to understand how best to use this technology.

Full Threads Newest First

Showing messages 1 through 1 of 1.

  • Why extend Dao?
    2006-07-08 18:42:14  Fucema [View]

    Most companies or developers end up writing their own lightweight DAO layers. In those cases they are going to have to distribute their custom DAO API anyways. In the case of Ibatis DAO, you are using a premade DAO layer so you will be sharing that API. In either case, you will have a DAO layer that will have some dependencies. You will have to distribute youre DAO API whether you write your own DAO or use iBatis DAO (which is different from iBatis SQL Mapper).

    <quote>Well, ideally, you'd like to have your interfaces be unconcerned with how the thing is actually implemented behind the scenes.</quote>
    That's the point of having a DAO layer - whether its IBatis DAO or something you write on your own, you are abstracting the actual persistence implementation. Perhaps you are getting the IBatis DAO confused with the IBatis SQL Mapper.

    <quote>Now, you've introduced a dependency on the iBatis Dao interface which requires us to have the iBatis jar in the client's classpath, when the client could care less that we're using iBatis behind the scenes on the server.</quote>
    The IBatis is just the DAO layer -- you would some sort of DAO implementation at that level whether you use IBatis or roll your own. So I don't see what your point is.

    The benefit to using IBatis DAO is that you have access to a pretty robust implementation that allows you to swap in different persistence implementations behind the scene. It's all about code reuse wherever possible, at least for me. And IBatis has alot of advantages in that area. Why rewrite a DAO layer everytime you start a new project at a different company or contract.