• Post Reply Bookmark Topic Watch Topic
  • New Topic

I don't understand interfaces  RSS feed

 
Miri Yusifli
Ranch Hand
Posts: 43
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I researched about interfaces but i dont understand that when i should use interface ? What are advantages of interface ?
 
Dominique Ubersfeld
Greenhorn
Posts: 7
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a good practice to use an interface when you want to hide all implementations details. Here is simple example:

You have an application that allows a Web browser to interact with a database. You create two layers:

1) The web layer that is responsible for all requests handling like GET and POST (it could be a servlet or a Spring controller)
2) A DAO layer that is in charge of all database access

You declare an interface named e.g. DAO that exports methods named insert(), remove(), update()

Then you create an implementation of your DAO interface named e.g. DAOOracle or DAOMySql depending on the actual DB you plan to use.

You make the web layer aware of the interface only, not of the implementation. In this way you can later change your database for a different one without having anything to change in your Web layer. So using an interface is mainly about clean coding and software maintainability.
 
Khuzema Dharwala
Ranch Hand
Posts: 61
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell what is the thing which is making you difficult to understand interface.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!