472,958 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

implement interface

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
Jun 27 '08 #1
5 2331
Tony Johansson wrote:
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
The person writing that description probably didn't think of that
special case, or throught that it was more important to keep the
description simple, than to make it cover every possible aspect.
--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #2
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

Jun 27 '08 #3
On Fri, 06 Jun 2008 15:57:19 -0700, Tony Johansson
<jo*****************@telia.comwrote:
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.
It is said by whom? How do they define the term "implements"?

As Scott said, interfaces are _implemented_, not inherited. But even
ignoring that mistake in your terminology, it's perfectly reasonable to
say that a class that inherits some implementation does in fact in some
sense implement both the inherited implementation and new implementation.

Anyway, it's really hard to say one way or the other whether a specific
statement is accurate or not without you actually posting the statement
and the full context in which it was made.

Pete
Jun 27 '08 #4
Tony Johansson expressed precisely :
Hello!

It is said that a class must implement all the methods in the interface it
inherits.
I think it depends on what you mean by "implement a method".

If it is strict "must physically define this method within this class",
then the above statement is false.

If it is the more broad "an instance of this class should have this
method, either directly or through inheritance", then the statement is
true. And your example would not violate it.

Hans Kesting
Jun 27 '08 #5
I think you're confusing things for the OP.

There really isn't (or shouldn't be) a dual meaning for "implements". A
method is implemented when a class provides functionality that the interface
requires and that functionality matches the name/signature that the
interface requires.

If a class inherits from a class that implements a method, the derived class
does not implement the method, but instead has an implementation of the
method.

In other words, implementation occurs at the level where the method is
provided to the class.

-Scott

"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
Tony Johansson expressed precisely :
>Hello!

It is said that a class must implement all the methods in the interface
it inherits.

I think it depends on what you mean by "implement a method".

If it is strict "must physically define this method within this class",
then the above statement is false.

If it is the more broad "an instance of this class should have this
method, either directly or through inheritance", then the statement is
true. And your example would not violate it.

Hans Kesting


Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter | last post by:
I want to copy a parent class instance's all datas to a child's. It's actually a C++'s copy constructor. But why the following code does not work - there is a compile error! How it should look...
2
by: Derrick | last post by:
Is there an implement interface wizard is C#/Visual Studio? And, I have an interface, with many implentations, want to provide a Web Service implementation. What would be the standard practice? ...
3
by: Brett Hall | last post by:
I have a VB.NET interface that my managed C++ code is to implement. I seem to be stuck implementing an event defined in that interface. Does anyone have a simple code snippet that will show me...
2
by: Dave | last post by:
I'm trying to extend the System.IAsynchResult so I created a class as follows: public class MyAsynchResult : System.IAsyncResult { ..... } But get: ...
14
by: Jim | last post by:
I am using VB.Net 2.0 and I am completely new to the concept of implementing interfaces. Can anyone explain "implementing interfaces" to me and perhaps give me an example of implementing an...
7
by: moondaddy | last post by:
If I'm in a class that inherits an interface, is there a shortcut key that will write the implementation of the interface into the class? I remember seeing something like this in vb.net. ...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
4
by: =?Utf-8?B?QmFqaS4=?= | last post by:
Hi, Can somebody suggest me, how can I implement a vc++ interface in C#.net. This interface has method CallMe( ) which is used as a CallBack from my main application. Thanks, Baji.
3
by: =?Utf-8?B?Sm9uIEU=?= | last post by:
I have an interface class with maybe eight functions, defined in one workspace and am defining a class in a second workspace that derives from this interface. Unfortunately only 7 of the 8...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.