473,545 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2386
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.com wrote 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.com 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.
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*********@sp amgourmet.comwr ote in message
news:Oq******** ******@TK2MSFTN GP02.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
17175
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 like? (The background is I don't know (I don't care indeed) all members in DataGrid, so I don't want to copy all members in DataGrid one by one.) ...
2
2564
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? Implement the interface in the main asmx class? Or just have all interface methods available, but without explicitly implementing it? Thanks in...
3
2706
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 the basics of what I need to implement? I've seen all the MSDN articles on implementing events in managed C++ and I've gotten events to work without...
2
4322
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: C:\Inetpub\wwwroot\MyApp\MyAsynchResult.cs(8): 'MyAsynchResult' does not
14
1739
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 interface that would help me implement the IIneternetSecurityManager interface mentioned under "Creating a Customized URL Security Manager" on...
7
15653
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. Thanks. -- moondaddy@nospam.nospam
52
20830
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 'UselessJunkForDissassembly.IInvocableInternals.OperationValidate(string)' C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535:...
4
4229
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
15744
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 functions in my derived class compile whilst just one of them refuses to be recognised, leading to an error message "...does not implement interface...
0
7496
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7428
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7941
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5354
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.