It is said that a class must implement all the methods in the interface it
inherits.
Well no. A class must implement all the methods of the interface it
"implements". Classes do not "inherit" interfaces. Implementation and
inheritance are not the same thing and thus, the source of your confusion.
MyDerivedClass doesn't have to implement DoSomething() because it is
inheriting the implementation of DoSomething() from the base class. It does
have to "implement" DoSomethingElse() because the class "implements" the
interface.
So, when a class "inherits" from a base class, it inherits all that the base
class has. When a class "implements" an interface it is entering into a
contract that requires that the entire interface be implemented.
-Scott
"Tony Johansson" <jo*****************@telia.comwrote in message
news:jh*****************@newsb.telia.net...
Hello!
Assume you have the following interface and classes shown below.
It is said that a class must implement all the methods in the interface it
inherits.
Below we have class MyDerivedClass that inherits IMyInterface but
MyDerivedClass doesn't implement method DoSomething() it inherits it from
the base class MyBaseClass.
So the statement that a class must implement all method in an interface
that it inherits is not fully true as I see this matter.
Do you agree with me ?
public interface IMyInterface
{
void DoSomething();
void DoSomethingElse();
}
public class MyBaseClass
{
public void DoSomething() { }
}
public class MyDerivedClass : MyBaseClass, IMyInterface
{
public void DoSomethingElse() {}
}
//Tony