Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to code client of DAO?

 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying my hand at using the DAO pattern but I doubt if I'm using it as it is meant. For the time being I'm calling the JDBC implementation (which is all that I'm going to need at this point).

Is retrieving the data in the main method for serious use case a good thing? I was reading old posts and a bottom post showed using the DAO with the help of dependency injection? I've never used dependency injection and would like to know how it would come in handy here.

Do let me know your thoughts and how could I improve my code.

Here is the code getting the data from the persistent store,

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dependency injection would remove the dependency between your client class and the JdbcCustomerInfoDao class. So all the client knows would be CustomerInfoDao which would typically be an interface.
Dependency injection however requires some libraries that implement it to be available in your client environment. Popular ones are CDI , Spring and Google's Guice.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response. It definitely helps me in getting started with DI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic