Results 1 to 6 of 6

Thread: Problem with Inheritance and interfaces

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Problem with Inheritance and interfaces

    Hello,
    I have a variable (interface) on which I would call a personal method (call it "foo").
    Code:
    NodeList ch = ((Node)parentElement).GetChildNodes();
    ch.toto();
    My 1st reaction was to extend through a NodeList MyNodeList class where I implement "foo". Unfortunately, I can not extend it since NodeList interface. How to do this properly? I could do it via a static method that I spend the NodeList but not top.
    Code:
    NodeList ch = ((Node)parentElement).GetChildNodes();
    Toto.toto(ch);
    Thank you in advance for your help

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Problem with Inheritance and interfaces

    Hello,
    You could make an interface NodeList mNodeListInterface who will implement and then a class mNodeList who will implement your new interface. You did not even need to make a new interface you can directly implement NodeList with mNodeList. I hope this will help you, if you have any query then please do post back and we will try to solve your problem.

  3. #3
    Join Date
    Dec 2009
    Posts
    204

    Re: Problem with Inheritance and interfaces

    Hello,
    Even I had a similar kind of a problem, so I tried this:
    Code:
    Public class mNodeList implements NodeList
    but the problem is that I must then re-implement other methods of the NodeList interface and it is not at all helpful. I event tried what you have mentioned in your post but that did not helped. If you have any alternate solution for this then please do help me.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Problem with Inheritance and interfaces

    Hello,
    I think you can create an abstract class that implements that your method:
    Here is the code for it
    Code:
    Public abstract class MyNodeList implements NodeList 
    {
    	Public void met() 
    	{
    		/ / ... code
    	}
    }
    Just try this method once and see if it is helpful. If you come with an error or you get and compile time error then post back with the error.

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Problem with Inheritance and interfaces

    Hello,
    You can also extend an interface (it's quite possible), though it is little compicated to do but works very well. Before that if you do not know the concept of this then please read it first.
    Here is the sample code for it
    Code:
    Public interface mNodeList extends NodeList 
    {
    	Public void metod();
    }
    But I'd like to know the reason for this ... That sounds a little odd in this case (you should not you worry about implementing NodeList normally).

  6. #6
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem with Inheritance and interfaces

    Hello,
    Conceptually speaking, an interface provides you services that you 'subscribers' your class that implements it. So normally, you're supposed to need the methods it provides. Although the underlying mechanism is similar implement an interface is different from a simple inheritance which is a specialization / generalization. I hope you have understood the points that I have tried to explain you.

Similar Threads

  1. Need the best audio interfaces
    By Cajetan in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-02-2011, 06:02 AM
  2. Replies: 3
    Last Post: 08-01-2011, 06:32 AM
  3. Programming in Android, problem of inheritance and object handling
    By Lalitmohan in forum Software Development
    Replies: 5
    Last Post: 27-11-2010, 12:06 PM
  4. Problem with inheritance in java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 12:10 PM
  5. Importance of c# Interfaces
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 08-02-2010, 07:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,538,462.02284 seconds with 16 queries