![]() |
Interfaces
Hi, I am very confused with interfaces. I understand how to use them and when to use them. I understand the difference between the abstract class and interfaces. Can someone explain to me the real importance of using an interface, because according to me it seems as if we declare an interface so all other classes can use the same name for a particular method. Why don't people just declare the same name in each class rather than having to go through something just to use the name?
|
Re: Interfaces
I am even more confused over how you're managing to skip from learning about "For Loops" and "Conditional Operators", to learning about Object Oriented Programming with Interfaces in Java.
Either you're going too quickly, or you're trying to understand things you don't yet need to. Regardless, maybe you need to spend more time on the square before this one, to gain further insight into programming before you ask these questions. I can promise the answers will make more sense that way, and you may not even need to ask this question when you get to that point. |
Re: Interfaces
Hi Sane I appreciate your help. I don't think I am going to fast, I just need an explanation, do you mind giving me one.
|
Re: Interfaces
Quote:
:
In Java, you can implement any number of interfaces but extend only a single class, which is another reason interfaces are used (other languages such as C++ allow for multiple inheritance). To put it simply, you should only extend a class when the class you are creating has an "is a" relationship with the class you are extending; for example, a GraduateStudent "is a" Student. In contrast, a Student might be able to fly, and would implement the Flyable interface. (Clearly, the Student does not have an "is a" relationship with his/her ability to fly.) |
Re: Interfaces
Used like callbacks and function pointer replacements.
|
Re: Interfaces
Quote:
|
Re: Interfaces
Quote:
In java, there are no function ptrs. So, we use interfaces with a method like eventCallback(Event e) that each sub/class has to implement and just call that method. |
| All times are GMT -5. The time now is 3:27 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC