Re: interface implementation and inheritance.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Mar 26, 6:57 pm, "Peter Duniho" <NpOeStPe...@xxxxxxxxxxxxxxxx>
wrote:
On Wed, 26 Mar 2008 14:06:02 -0700, parez <psaw...@xxxxxxxxx> wrote:
The following compiles.. Is this expected behavior?

Is what "expected behavior?

If you're using C# 3.0, then yes...I don't see any reason what you posted
wouldn't compile. But whether it does what you really want it to do, I
can't say. You haven't declared class A as implementing Interface2, even
though it does appear to. Nor does the code appear to address the
question you originally asked (that is, having the implementation of a
single interface spread across multiple classes).

But if the code does what you want it to do, seems fine to me. :)

Pete

Code does address the original question...

Is it a good idea(or is it possible) for to implement half an
interface in base class and half in derived class.

Half (i should have said some) of MyInterface is implemented in
Class A (base class) and half in Class B.

Yes.. It does do what I want it to do..

And why should it work only in c# 3.0? I am using .net 3.0( i think is
c# 2.0)


TIA




.



Relevant Pages

  • BadImageFormatException with Reflection.Emit
    ... We have C# class librarywith interface definitions: ... void SomeMethod(); ... Also a class librarywith base class BASE defined. ... In my real program the compiler does compile the end dll without errors, ...
    (microsoft.public.dotnet.framework)
  • Re: I dont understand inheritance!
    ... Look up explicit interface implementation to answer the majority of your ... which your subclasses can override. ... > //this does not compile, compiler says: ... > /* here i cannot override this method that the base class implements ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: C++ header file
    ... There is no reason not to do that, in fact the compiler does allow that. ... the interface and would have to compile the whole code, ... there must be a header file map to it. ...
    (microsoft.public.vc.language)
  • Re: Using abstract class that implements interface
    ... An abstract base class can define an interface for this purpose just as well as an interface. ... In Java it is adviced for a lot of reason to "program to ... Abstract classes are a bad choice for a lot of reason. ... If the base class is something that needs to be mocked for testing, and the mock can't conveniently be constructed as a subclass, then that's a perfectly good reason to refactor out an interface. ...
    (comp.lang.java.programmer)
  • Re: protected interface members
    ... There's no reason you can't delcare something 'protected abstract' in your base class. ... Is there a reason you need to have an interface over an abstract class? ...
    (microsoft.public.dotnet.languages.csharp)