Re: I don't understand inheritance!
From: Matt Gerrans (matt.gerrans_at_hp.com)
Date: 12/03/04
- Next message: Robby: "Re: Possible TRY...CATCH...END TRY"
- Previous message: Ollie: "Re: Possible TRY...CATCH...END TRY"
- In reply to: Francois: "I don't understand inheritance!"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Robby: "Re: Possible TRY...CATCH...END TRY"
- Previous message: Ollie: "Re: Possible TRY...CATCH...END TRY"
- In reply to: Francois: "I don't understand inheritance!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|