Interfacing an interface

Hi,

How can I achieve something like the below code? I'm not looking for InterfaceB to implement InterfaceA, nor do I wish for InterfaceB to inherit interfaceA, as that would mess things up slightly.

Thanks,
Uni


Interface A
   sub subA()
End Interface
 
InterfaceB
   sub subA()    //From InterfaceA
   sub subB()
End Interface

Open in new window

LVL 3
Unimatrix_001Asked:
Who is Participating?
 
abelConnect With a Mentor Commented:
One other thing comes to mind: that is if you want to force aggregation to classes implementing your interface. I.e., when they must have a certain method exposing the other interface. In that case, it would be something like this:

Interface InterfaceB
   Function getObjectWithInterfaceA() As InterfaceA
   Sub subB()
End Interface
0
 
abelCommented:
what are you trying to say, you want to implement an interface but not inherit it? In that case, you already did it.... can you be a bit clearer on what you're after?
0
 
Unimatrix_001Author Commented:
No, I don't want to implement it - I'm looking for a way for any class inplementing interface B to have to implement interface A also - without interface B inheriting interface A.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
abelCommented:
Well, that is basically a contradictio in terminus, the whole idea of interfaces and inheritance is that you can force a certain layout of a class with it.

The only way to really force that any class implementing Interface B is also implementing Interface A is by making sure that Interface B inherits from Interface A. But you say you do not want it.

Normally, these things are documented the other way around. I.e., if you want to have certain Dispatch behavior, you implement IDispatch. if you also want your object to be cloneable, you should implement ICloneable as well. That's the way interfaces should work: they expand the possibilities of your class. And I agree that normally you do not inherit from an interface in a new interface.

But forcing this behavior is currently only done through documentation. Saying "if a class wants to support this behavior, it should implement this interface" and then follow a lot other rules, describing how the interface should be implemented.

All in all, interfaces are pretty weak contracts, but it still serves a string purpose if done well and if people abide the documentation when implementing an interface. I know it may sound silly, but the real answer to your question is "put it in the documentation of your interface".

Sorry, but there's no other news about this. It is part of a very basic OO principle and all languages I know of work like this when it comes to interfaces (there are differences, but only in the details).

-- Abel --
0
 
Unimatrix_001Author Commented:
Thank you. :) Support for multiple inheritence within .NET would really make my life much easier... :(
0
 
abelCommented:
oh, maybe I misunderstood you, or you misunderstood me. Multiple class inheritance indeed is not supported, but multiple interface inheritance is supported. You can have as many interfaces as you want in the inheritance declaration of a single class declaration.

On a side note, as far as I know, only Bertand Meyer managed so far to implement multiple inheritance in a dotNet language: Eiffel.Net (based on Eiffel). It was considered undoable at the time, but he did it regardless and flawlessly. So it can be done.

Public Class MyTestClass
        Implements ICloneable, ICollection, IDisposable, IConvertible, IComparable
 
End Class

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.