![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2008
Posts: 15
Rep Power: 0
![]() |
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?
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
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. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2008
Posts: 15
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 | |
|
Expert Programmer
|
Re: Interfaces
Quote:
Java Syntax (Toggle Plain Text)
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.) Last edited by titaniumdecoy; Jan 7th, 2008 at 6:45 PM. |
|
|
|
|
|
|
#5 |
|
12 years old
Join Date: Nov 2007
Posts: 94
Rep Power: 1
![]() |
Re: Interfaces
Used like callbacks and function pointer replacements.
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
Re: Interfaces
|
|
|
|
|
|
#7 |
|
12 years old
Join Date: Nov 2007
Posts: 94
Rep Power: 1
![]() |
Re: Interfaces
When you have a callback, in c++ event handling, you pass a function ptr so it calls it each time when an event occurs.
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. |
|
|
|
![]() |
| 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 |
| Programming Interfaces | surf3rb0y | Visual Basic | 1 | May 20th, 2007 11:11 AM |
| interfaces | paulchwd | C# | 0 | Feb 18th, 2007 1:45 PM |
| Java-style interfaces in C++ | gizzy | C++ | 24 | Feb 19th, 2006 1:33 AM |
| Aren't interfaces useless? | Simon Gray | C# | 15 | Sep 1st, 2005 4:40 PM |
| Graphical User Interfaces | Clotters | Other Web Development Languages | 11 | Jul 18th, 2005 4:20 PM |