Announcement Announcement Module
No announcement yet.
Why getJdbcTemplate in JdbcDaoSupport not protected Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why getJdbcTemplate in JdbcDaoSupport not protected

    is there a reason why the method getJdbcTemplate in the class JdbcDaoSupport is made public and not protected? I thought the purpose of the method getJdbcTemplate is to provide a JdbcTemplate to DAO subclasses. For that purpose protected would be sufficient. But by making this method public all clients using the DAO subclass can access the JdbcTemplate by calling getJdbcTemplate and make database calls bypassing the DAO layer.
    So would`t it be a better design to make the method protected in JdbcDaoSupport to prevent such usages?

    Thanx for your replies.

  • #2
    Yep you're right (I try to thing about not extending but aggregating JdbcDaoSupport but this is rather dummy example).

    I think that the main reason is to follow JavaBean public getter/setter convention.


    • #3
      Probably for test purposes. That way, you may check externally that jdbcTemplate was correctly injected, and even meake a few tests to connection