I read early posts. Addition to this I am reading Sun's tutorial. But I find hard to understand interface.
Can we say interface provides interaction between Java developers who are working on the same project? Is it right?
How do they manage this? Only with implements keyword?
Serap Elbeyoglu
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
4
posted
0
It might provide interaction between two people working on the same project. But it provides much more. If you say "implements List" then you know there are 25 methods which are available, and what they do, but you don't know how they are implemented.
Serap Elbeyoglu
Ranch Hand
Joined: Feb 12, 2010
Posts: 52
posted
0
Thank you Campbell Ritchie,
Can you explain more? One of the function of implements is providing interaction between developers. I got this. What are the other functions?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
4
posted
0
An interface indicates there is a consistent range of functionality. As I said, "implements List" means there will be 25 methods, which you will find in the List interface.
Serap Elbeyoglu
Ranch Hand
Joined: Feb 12, 2010
Posts: 52
posted
0
Thanks a lot Campbell,
I have made some research. I think I got some point of interfaces. It is not so difficult as I supposed.
I have opened a new topic about writing flexible code. Please visit it.
You and I both work at the same software company. We need to buy third party software for controlling a robotic arm. We are competing for a huge bonus.
The third party I use provides an interface. They give me a list of methods their class will implement. I write me code to call those methods. I don't know, or care, how they work internally, I just know the method signature. So I write my code to call 'raiseArm(3)' or 'turnXAxis(15)'.
The day before my presentation to the board, my 3rd party vendor has a brand new release that is 10 times more efficient. Since their new code uses the same interface, I don't have to touch my code - I just drop in their new compiled classes.
Your third party gives you a list of methods. You write your code calling these explicit methods. They day before your presentation to the board, your vendor releases a new version that is 10 times more efficient. But all their method names changed from something like 'raiseArm()' to something like 'raiseArm2()'. For hundreds of methods.
Do you a) go in front of your board of directors and say "We're using the old version of the vendor software that is slow", or b) Spend all night re-writing your code to call the new methods, re-testing and validating every line?
Notice that since my code didn't change, I don't have to re-test it. You do. And in six months, when both vendors come out with their version 3.0 software, I can be sipping a cocktail on a beach spending my bonus money, while you have to work ANOTHER all-nighter to get your code working again.
Serap Elbeyoglu
Ranch Hand
Joined: Feb 12, 2010
Posts: 52
posted
0
Fred, it is a great explanation. Thank you, it is so clear to understand the necessary for interfaces.
You and me will compete again and I will get the big bonus