Thursday 15 September 2011

inheritance - Implementing Inherited Interface with Overloaded Member vb.net -


I am trying to implement the derived interface in a class. My interface and class are similar to the following: I namespaces are different projects that are related to these interfaces and square hold: Names1 Names also Ns1 Public Interface IParent function myfunction () Double end interface termination Ns1 also named Place ns2 public interface IDerived inherited ns1.IParent as overloads / myfunction function (byRef myObject as object) Double end interface termination ns2 namespace NS3 public class myClass Impli Ents the ns2.IDerived public function as myfunction (as in the form of ByRef obj object) double implements as ns2.iderived.myFunction End Function NS3

Am I doing what I am trying to do - implement only the function of the interface I derive from the class - using the interface? If there is no way to use the interface, can someone recommend alternative options? We really need to use the interface and are trying to avoid using classes. He said, intangible classes, I am allowed to do everything to do this to me.

I have read a lot of information on all topics related to this question because every concept is very basic and well covered online help.

Thanks in advance for any help.

I do not know that this is a typo, but you have two different methods: one that No parameter, and the second one takes the object, so the compiler's requirement is valid. / P>

If this is a typo and you have only one method, then " myFunction () ", then I'm afraid VB.Net C # just by hiding the base interface and allowing only one to apply the derivative.

And you can fix it easily by forwarding it:

  Namespace ns1 Public Interface ipurate function myFunction () Double end interface termination namespace name space ns2 public interface IDerived inherited ns1.IParent function myfunction () Double end interface termination namespace name space NS3 Public Class Class1 Implements ns2.IDerived public function myfunction (as) double implements as ns2.IDerived.m as yFunction Return 42 Expiration Event Private Function myFunction1 () Double Implements ns1.IParent.myFunction return myfunction () Expiration Function Expiration Class Expiration Namespace Module Module1 Sub Main () Dim CP ns1.IParent = New ns3.Class1 as cp.myFunction () Dim cd as ns2.iderived = New ns3.Class1 cd.myfunction () End Sub End Module   

Edit: Then there was no typo, Here's the standard (good / best practice?) Fix:

  Public Classroom Class 1 implementation, ns 2.n Defined Public Function myFunction (ByRef obj as Object) Double Implements as ns2.IDerived.myFunction End Function Public Function myFunction () Double implements as ns1.IParent.myfunction Throw new non-imaged exception ("ns1.IParent" .myfunction 'has not been implemented because Unicorn can not fly!) End Function and Class    

No comments:

Post a Comment