[Highschool - computers] I don't understand the purpose of interfaces. (In java)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dooey100
    FFR Player
    • Sep 2006
    • 370

    #1

    [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?
  • tsugomaru
    FFR Player
    • Aug 2004
    • 3962

    #2
    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
    Originally posted by Hiluluk
    WHEN do you think people die...?
    When their heart is pierced by a bullet from a pistol...? No.
    When they succumb to an incurable disease...? No.
    When they drink soup made with a poisonous mushroom...? NO!!!
    IT'S WHEN A PERSON IS FORGOTTEN...!!!

    Comment

    • sleeplessdragn
      ~Bang that beat Harder~
      FFR Simfile Author
      FFR Music Producer
      • Jan 2004
      • 2321

      #3
      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.

      Comment

      • dooey100
        FFR Player
        • Sep 2006
        • 370

        #4
        Re: [Highschool - computers] I don't understand the purpose of interfaces. (In java)

        Ah, that makes sense. I never thought about team/group projects.

        Comment

        • skishmonkey72
          FFR Player
          • Nov 2006
          • 366

          #5
          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.
          Last edited by skishmonkey72; 01-20-2008, 10:49 PM.
          One Handers Ranking List

          Comment

          Working...