Re: I don't understand inheritance!

From: Matt Gerrans (matt.gerrans_at_hp.com)
Date: 12/03/04


Date: Fri, 03 Dec 2004 10:00:36 GMT

I forget all the rationale behind this, because it was a while ago that I
read the material (when I was first learning C#), but the problem is that if
the base class chose to implement the interface methods with the
InterfaceName.method() signature, they cannot have access modifiers and
cannot be virtual. If you have this interface:

interface IFace
{
   string foo();
}
You could do this to satisfy it:
class Base1 : IFace
{
   public virtual string foo() { return "virtual foo from Base1"; }
}
and then you could override it:
class Derived1 : Base1
{
   public override string foo() { return "virtual foo from Derived1"; }
}
but if you did this:
class Base2 : IFace
{
   string IFace.foo() { return "IFace.foo from Base2"; }
}
You would satisfy the interface, but could not add the public and virtual
modifiers, so you couldn't override it. You can also do both:
class Base3 : IFace
{
   public virtual string foo() { return "virtual foo from Base3"; }
   string IFace.foo() { return "virtual foo from Base1"; }
}
And in this case, you can override the virtual foo().

Anyway, it looks like in your case, the CheckBox class has implemented the
interface as in case 2, so the designer of that class didn't plan for you to
override those methods.

- Matt



Relevant Pages

  • Re: I dont understand inheritance!
    ... If you have this interface: ... class Base1: IFace ... so you couldn't override it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: I dont understand inheritance!
    ... you can't override Interface methods that aren't marked as ... public abstract void DoSomething(); ... > IPostBackDataHandler (notice the interface that is implemented) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: I dont understand inheritance!
    ... you can't override Interface methods that aren't marked as ... public abstract void DoSomething(); ... > IPostBackDataHandler (notice the interface that is implemented) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Deriving - .NET example
    ... that existing interface will be supported in the future versions, ... If the class had a small interface, I wouldn't think twice - the inheritance approach would not seem appropriate. ... Of course I would not choose the approach to code and not to use designer. ... If I need to override, ...
    (comp.object)
  • Re: Discussion: "Why Visual Studion 2005 is better then BDS 2006?"
    ... This should put in the declarations. ... interface and every method I could override. ... The BDS code templates are also context sensitive. ...
    (borland.public.delphi.non-technical)