|
|
Thread Tools | Display Modes |
01-20-2008, 03:45 PM | #1 |
FFR Player
Join Date: Sep 2006
Posts: 370
|
[Highschool - computers] I don't understand the purpose of interfaces. (In java)
Hi, I'm taking a course in java programming and I just learned how to use interfaces. I know how to use them properly, but I don't see the point. You still have to write the methods for each class that uses the interface, and the only reason I see to use an interface would be to make sure you don't forget any methods.
I know that you can use interfaces for constants, but unless you have a lot of constants, if wouldn't be much trouble to put the constants with all the other variables. I haven't done any big projects with many classes yet, so they may be more useful in practice then it looks like. On a slightly unrelated note, didn't there use to be a board for programming? |
01-20-2008, 04:13 PM | #2 | |
FFR Player
|
Re: (Highschool - computers) I don't understand the purpose of interfaces. (In java)
We used to have a programming board but it was shut down due to inactivity. I remembered at one point when there was less than one thread created per month. If you have a question like this, your answer would be better answered on a Java programming forum because more people know what they are doing there or the answers may be found there.
~Tsugomaru
__________________
Quote:
|
|
01-20-2008, 05:10 PM | #3 |
~Bang that beat Harder~
Join Date: Jan 2004
Posts: 2,321
|
Re: [Highschool - computers] I don't understand the purpose of interfaces. (In java)
It is often nice, when writing code that other people will be using, to force them into a path, so to say. Interfaces let you keep your code scheme very apparent, as well keeps things clean and easy when dealing with projects that involve heavy inheritance.
|
01-20-2008, 07:21 PM | #4 |
FFR Player
Join Date: Sep 2006
Posts: 370
|
Re: [Highschool - computers] I don't understand the purpose of interfaces. (In java)
Ah, that makes sense. I never thought about team/group projects.
|
01-20-2008, 11:40 PM | #5 |
FFR Player
|
Re: [Highschool - computers] I don't understand the purpose of interfaces. (In java)
Like sleeplessdragn said, it's really helpful in team projects to have specific classes in a project to implement a particular interface, so one can expect certain things from an implementing class. Another thing is for when you want to have classes inherit certain things. It doesn't always make sense to have a class to inherit everything from a superclass. For example, Arabian can extend Horse, and inherit methods and variables specific to any Horse, but it could also implement Rideable, and inherit specific methods and constants required for a Rideable object. (Rideable objects are not necessarily Horse objects, but could also be something like Camel). But you can't necessarily put those methods and constants in the Horse superclass, because not all horses are intended to be ridden. In short, interfaces are a useful way to circumvent or model multiple inheritance.
__________________
One Handers Ranking List Last edited by skishmonkey72; 01-20-2008 at 11:49 PM.. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|