• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

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

0
Unimatrix_001
Asked:
Unimatrix_001
  • 4
  • 2
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
abelCommented:
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now