This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interfaces

 
Mathavan Balakrishnan
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends

I want to know what is the actual use of interfaces in java.

I know that interfaces have methods that are not implemented.

Why do we use a thing that doesn't have any implementation ?

Can't we accomplish our task without interfaces ?

What is the speciality of interfaces ?

What interfaces can do that classes can't do ?

Can u please illustrate the use of interfaces with examples ?

Waiting for ur reply friends.

urs
Mathavan
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathavan Balakrishnan:

Why do we use a thing that doesn't have any implementation ?


Let's change your question a little bit. How does a class look to a client? Isn't it just a bunch of method invocations? The client has a type and one or more associated operations for that type. Given a reference type String, a client may invoke one of many available operations. Sometimes the client only wants a subset of those operations, but in any case, the client is exposed to many operations ("needle in a haystack") implied by the so-called "OO paradigm". Then, the client "interfaces" to an implementation through a very strict and formally defined contract. Isn't it then obvious what the advantages are of separating that contract from the implementataion of the contract?

Think a bit more. I won't do your homework for you
 
wise owen
Ranch Hand
Posts: 2023
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic