Question Could Someone Please Explain Interface Inheritance?

jayware33

Member
Joined
Jan 15, 2010
Messages
13
Programming Experience
Beginner
jst really looking to get a bit of basic information about what interface inheritance actually is, nothing too complex now, just the basics, the fundamentals really.



thanks
 
thanks for the reply but that just confuses me even more :( it goes way too in depth and by the looks of it, the whole detail about polymorphsim, i can hardly say the word let alone implement it lol.... i have a beginers course here and the books i have dont make much sense so im trying to redefine the terms of what is being said, so i can perhaps understand it from someone else explaining it to me. could you or someone else give a short explanation of the very basics of what it means ... i have an understanding of objects, properties, methods ect
when they talk about interfaces, do they mean the actual user interface? or somethign else such as "under the bonnet" stuff lik ehow the methods are layed out ect? thats whats confusing me, i think they mean the interface as in what the EU sees?
 
This short article explains in simple terms what an interface is: Interfaces Overview

I will submit a practical basic example that perhaps can enlighten you some more. Let's say you have this interface defined:
VB.NET:
Interface IContract
    Sub MethodA()
End Interface
And this method that take any kind of object implementing this interface as parameter:
VB.NET:
Sub RequireObjectWithContract(ByVal x As IContract)
    x.MethodA()
End Sub
This method can safely call the MethodA member, because any object supplied to the x parameter must be of type IContract.

Then you may have these two different classes that implements the interface:
VB.NET:
Public Class TestThis
    Implements IContract

    Public Sub MethodA() Implements IContract.MethodA
        MsgBox("TestThis A")
    End Sub

End Class

Public Class TestThat
    Implements IContract

    Public Sub MethodAnything() Implements IContract.MethodA
        MsgBox("TestThat A")
    End Sub

End Class
Notice that in TestThat class I named the Sub "MethodAnything", but it is still an implementation of the MethodA member of the IContract interface. Normally the implementing member name doesn't differ from the interface member name, I just did this so you can see how the consumer sees this object. As a IContract object the RequireObjectWithContract method calls MethodA regardless.

Now you can create instances of these classes and pass them as arguments to the method:
VB.NET:
Dim obj1 As New TestThis
Dim obj2 As New TestThat
RequireObjectWithContract(obj1)
RequireObjectWithContract(obj2)
Back to the orginal question, when it comes to "inheritance" I encourage you to read some more in the first article I linked to. Ignore the parts you don't understand try to get through the text, it really explains these aspects well.
 
thanks, that does help now i read over that. Think i will just need to take it slow and take one step at a time as i have a tendency to try and go into too much detail at first glance.


much appreciated.
 
Back
Top