• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface - reference  RSS feed

 
rudresh kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I would like to know what is the benefit of doing the coding as shown below

I have an interface ILoginDAO (which is an interface having a method called checklogin())

I have class called LoginDAO which implements this method.

What difference it makes by doing one of the below

a)
LoginDAO obj = new LoginDAO();
obj.checklogin();

b)
ILoginDAO obj = new LoginDAO();
obj.checklogin();

Both works, but i would like to know what impact it makes

Thanks in advance
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rudresh,
The main benefit is that it ensures you are "programming to interfaces." If the DAO has methods that the interface does not, it becomes easier to change concrete classes in the future knowing you are only using the interface.

It also makes it easier to refactor the code to be testable since an interface can be more easily mocked out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!