
| TechSiddhu | Nov 29, 2006 12:31am | | Hi, can anyonegtell me what are the possible implemenation areas of interfaces in Java. And y we really need them |
|
|

| heraclitus | Nov 29, 2006 8:54am | If I understand your question, Java does not permit multiple inheritance. That means a class can only have one parent class and this defines what it is. An interface specifies a group of abstract methods without being tied to any particular implementation. All a class must do is implement those methods and it can extend the interface (as many as desired/needed). One way of looking at it, according to "Learning Java" (O'Reilly), "They cut across the boundaries of what kind of object an item is and deal with it only in terms of what it can do." An interface adds functionality to an object.
Do we really need them? I suppose a person could program the funtionality into any class, but you would be doing the same things over and over and over again. Interfaces allow you to avoid that and simplify the programming effort.
"Learning Java" has a pretty good explanation.
Does that help? |
|
|

| TechSiddhu | Dec 11, 2006 9:21pm | | hey sorry for late response. that was really very helpfull .. |
|
|

| andygavin | Feb 27, 2007 8:12am | One of the key uses of an interface is to allow parts of the system to be decoupled: the implementation of some functionality is separated from how it is called. So it allows for patterns like the strategy pattern but also they allow for easy mocking: interfaces are often placed at strategic places throughout a large system to allow for subsystems to be tested independently by the injections of mocks during testing.
en.wikipedia.org/wiki/Mock_object [en.wikipedia.org/wiki/Mock_object] |
|
|

| teckey06 | Mar 2, 2007 7:51am | Thats right.
when parts are decoupled, they can be maintained and changed without impacting the rest of the App. So coding to an interface rather than direct making calls is always a better design. This gives flexibility to change the implementation anytime, without major impact. |
|
|

| andygavin | Mar 15, 2007 12:42pm | I came across a story recently of a developer who wrote an interface for every class he wrote. This isn't the idea. I find if you at least try to practice TDD then you end up with the right balance.
Another point is that the use of dependancy inversion is growing in popularity, the role of the interface is quite well established in this technique.
(I notice Google released their IoC Container this week). It is also well established in patterns, to get an idea of how interfaces ought to be used in good design. |
|
| Use of Interfaces in java | | |
You need to Sign-up for StumbleUpon to post to this forum
|