![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Java Developer
|
Implementing same interface multiple time in herarchie of class
I dont understand why we need to implement same interface through the herarchie of class
example : interface a {
}
class c implements a,a
{
}but interface a {
}
class c implements a
{
}
class d extends c implements a
{
}is working fine
__________________
[Pushkaraj] Imagination is more important than knowledge – Albert Einstein |
|
|
|
|
|
#2 |
|
Expert Programmer
|
|
|
|
|
|
|
#3 |
|
Java Developer
|
OK i think I have to make it more clear
Is there any good reason where we need to implement the interface in a class which is already implemented in some of its superclasses... If you are giving the reason as, "if we have to change the functionality", then we could simply override function insted. and if reason is, "If we have to get a reference of interface pointing the class object" then its already implementing the interface in superclass. but I want to know that what we get extra if we implement the interaface, in subclass.
__________________
[Pushkaraj] Imagination is more important than knowledge – Albert Einstein |
|
|
|
|
|
#4 |
|
Expert Programmer
|
If a class implements interface I, its subclasses also implement interface I. It makes no difference whether these classes explicitly implement interface I.
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 146
Rep Power: 2
![]() |
in short, you get nothing extra. might as well not specify em
|
|
|
|
|
|
#6 |
|
Newbie
|
It is a design trick
As you know ,interfaces are with no any implementation , we often make the implementation of it in subclass rather than super class .Because it will be needed only in this subclass for example
if we have a super class X and two sub classes Y & Z, now if we implement the interface in X both Y ,Z will also inherit it ,But it will be not a good OOP design if class Y need this interface and class Z don't.So in this case to make it more simple we make the implementation in the subclass Y only and this will decrease the lines of code and make it easier to understand, .So it is a design trick and depends on your software engineering work! . I hope what i wrote is useful to you my friend and good luck . ![]() |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
Quote:
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
|
#8 | |
|
Expert Programmer
|
Quote:
Imagine a non-abstract class A which implements interface I. As class A is not abstract, it must provide an implementation for any methods declared in I. Now imagine class B extends class A. Class B need not implement any of the methods declared in interface I as the implementations for those methods are inherited from its superclass A. However, if class B does provide implementations for some or all of the methods declared in I, those methods will take precedence over those defined in class A. In other words, when a method is called on an object, the VM looks for a definition first in that class, then in its superclass, and continues up the class hierarchy until an implementation is found. I recommend this problem from my CS AP class in high school. It covers all of this and may be easier to understand. |
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
It all makes sense now.
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
#10 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
To answer the OPs question, I think the reason that the implementation of an interface is made explicit when it's already implicit (due to a superclass implementing it) is to make things more clear. It is a good design idea, as it makes it easier for the programmer to determine if a given interface is implemented by a particular class (no need to check the hierarchy of classes). Functionally, though, it makes no difference.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Implementing a dynamic class | fhslacrosse13 | C++ | 6 | Nov 1st, 2006 3:56 PM |
| What is: "Oriented programming (OO)?" | BrinyCode | C++ | 12 | Nov 22nd, 2005 7:40 AM |
| C# Pilot Program | Haz | Existing Project Development | 9 | May 2nd, 2005 9:27 AM |
| creating class objects at run time | garr79 | C++ | 3 | Feb 8th, 2005 10:58 AM |