Inheritence and Interfaces !!


EJB programming & troubleshooting: Inheritence and Interfaces !!

  1. Inheritence and Interfaces !! (6 messages)

    Why java does not support Multiple inheritence ?
    and by Interfaces what functionality java want to give? Is there any Concept behind this ?Any one help me to overcome this problem !!! I already posted this at Forum on Sun site ,but people got me confused with c# and c++?

    Threaded Messages (6)

  2. Inheritence and Interfaces !![ Go to top ]

    Java supports multiple interface inheritance. That means a class can implement any number of interfaces it wants, but it can only extend one other class. Why is this? Who knows, but most people find multiple implementation inheritance nasty and error-prone and Java just avoided it all together.

    It really shouldn't be a problem. I've never come across a reason to have multiple implementation inheritance, nor have I heard about one, even from friends who do C++ primarily. It's usually something you want to avoid, like goto, because it means you are not solving the problem correctly.
  3. Inheritence and Interfaces !![ Go to top ]

    Interfaces allow your client code to not care how the object it is using is implemented. It seperates WHAT an object can do from HOW it does it. Its definitely more work up front to use interfaces, but it will pay off down the road.

    Great example of this is JDBC. If you look at the JDBC API's, its mostly interfaces. The implementation is left to the vendors. In your code that uses JDBC, you simply deal with Connection, ResultSet etc.. Your code doesnt care that its OracleConnectionImpl or SQLServerConnectionImpl behind the scenes. Your code knows it has a Connection and thats all that matters. You can switch to a differnet DB and (other than SQL differences)your code will not break.

    If your design your API's as Interfaces, you can change implementation w/o breaking your client code. It also makes your API's much more flexible. If you make your return types interfaces, then you can swap in/out new implementation easily. If your methods accept interface types rather than classes, they are more useful since they only care that what they receive implements a certain interface. You can pass in all kinds of objects. So many good reasons to use them, it just takes a little while to realize their worth.

    Hope this helps some...
  4. Inheritence and Interfaces !![ Go to top ]

    thanks Netsew Nekia !!
    Could u pl tell me,what will u say this functionality in Object oriented terms?
  5. Inheritence and Interfaces !![ Go to top ]

    Not sure I understand your question exactly but Ill try...

    Interfaces denote the concept of 'Type'. Your object can be differnet types and can be used based upon its type (Polymorphism).

    example: If you have a class named AmphibiousVehicle that implements both the Boat interface and the Car interface, then it can be used/referenced as either one of those types. You could pass an AmphibiousVehicle instance to a method that accepts a Boat or a method that accepts a Car. The object has 3 types (well 4 including Object). Its a Boat, its a Car and its an AmphibiousVehicle.

    Hope this helps some more...

  6. Inheritence and Interfaces !![ Go to top ]

    Mr. Nekia !! More help is required ...i am not able to clear the cocept.
  7. Inheritence and Interfaces !![ Go to top ]

    You should pick up a good book on OO design.

    'The Java Programming Language' by Arnold, Goshling and Holmes has a nice overview of OO concepts and interfaces as it relates to Java. What we are talking about is really just OO, so you could pick up any book on OO. Somtimes having Java examples helps if thats what you speak best.

    Good luck!