View Single Post
  #1 (permalink)  
Old 01-23-2008, 04:46 AM
frejon26 frejon26 is offline
Member
 
Join Date: Jan 2008
Posts: 7
frejon26 is on a distinguished road
interface purpose?
obviously interfaces have some kind of purpose but it is lost on me... I have searched high and low for an answer to this question and maybe someone here can help.
-So interfaces are java's way of implementing behavior when multiple inheritance is not tolerated, and it is also a sort of "contract" that a program binds with the interface, (if an interface declares a certain amount of methods, and a class implements the interface, the class must also implement all of the methods declared in the interface.)
Here is my question...
if all that an interface provides is "empty" method declarations (and some constants maybe), how does this add any functionality to a class? you still have to write the methods youself when you implement the interface, why couldn't you just write the methods yourself and not implement the interface? or for instance there is an interface "Serializable" for storing a class as an object for retrieval later, but what would this interface declaration look like?

public interface Serializable{
}

how would this add any functionality, or object "behavior"? it seems to me that there is a lot happening in the background other than just empty method declarations.
thanks ahead to anyone who can shed some light on these questions I've been having.
Reply With Quote
Sponsored Links