Shared methods derrived from interface

  • Thread starter Thread starter Elephant
  • Start date Start date
E

Elephant

Hello, question,

I want to make a COM-compatible .NET DLL (Visual Basic). For this I need an
interface. The DLL has a class that must contain methods that can be used
without making an instance of the class first.

So I have a class that has methods that derrive from an interface, and the
same class has methods that are Shared....but methods that are derrived from
an interface are not allowed to be Shared...

How to solve this? Any Tricks. Somewhere I read that this rule does not
apply to classes that are NotInheritable, but it doesn't work.

Any help would be great,

me.
 
Well, it's Friday, and it looks like the regulars around here vanished early.
I have limited experience with interfaces, but I'll take a shot at it since
you have not gotten a response yet.

I have 3 ideas:

1) If you implement a member from the interface, it cannot be shared. OK.
But if the same function could be morphed with a different signature,
probably by changing or adding a parameter, you could have a shared version
of the function in addition to the one required by the interface.

Public Function CleanMyHouse() as Integer Implements theClass.CleanMyHouse
'...
End Function

Public Shared Function CleanMyHouse(Shared as boolean) as Integer
'Ignore the parameter
'...
End Function

2) You can add members to a class that are in addition to the interface.
Similar to the above solution, but use different function names.

3) You could implement the interface, then remove references to the
interface, then allow members to be shared. This would not be a strict usage
of the interface, but might resolve the problem.

I am not sure about the COM requirements, so not sure if any of this will
work.

www.charlesfarriersoftware.com
 
Thank you Charlie,

if I understand correctly, the first two solutions require different
functions with the same functionality. That is out of the question. There
may be only one implementation. I had a similar solution ( normal shared
methods and a seperate class with an interface for COM which call those
methods ), but I hope there is a better way.
I think I don't understand option 3, but if I do, it won't help me.

But thanks again for the response,

me.
 
Back
Top