473,717 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about two interfaces derived from the same one.

Roy
If I have two interfaces derived from the same one. How do I implement the
methods in my class supporting both interfaces? I would like to have
different implementation for methods in base interface from different
interfaces.
Feb 17 '06 #1
3 1276
Hello, Roy!

R> If I have two interfaces derived from the same one. How do I implement
R> the methods in my class supporting both interfaces? I would like to have
R> different implementation for methods in base interface from different
R> interfaces

Here is code sample

interface IBase
{
void method();
}

interface IDerived1 : IBase
{
void method();
}

interface IDerived2 : IBase
{
void method();
}

class Implementor : IDerived1, IDerived2
{
void IDerived1.metho d()
{ }

void IDerived2.metho d()
{ }
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 17 '06 #2
Roy
Vadym,
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?

Thanks.
"Vadym Stetsyak" wrote:
Hello, Roy!

R> If I have two interfaces derived from the same one. How do I implement
R> the methods in my class supporting both interfaces? I would like to have
R> different implementation for methods in base interface from different
R> interfaces

Here is code sample

interface IBase
{
void method();
}

interface IDerived1 : IBase
{
void method();
}

interface IDerived2 : IBase
{
void method();
}

class Implementor : IDerived1, IDerived2
{
void IDerived1.metho d()
{ }

void IDerived2.metho d()
{ }
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot

Feb 17 '06 #3
Roy <Ro*@discussion s.microsoft.com > wrote:
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?


From the C# spec:

<quote>
The fully qualified name of an interface member must reference the
interface in which the member was declared.
</quote>

p was *declared* in IBase, not IDerived1 or IDerived2.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 17 '06 #4

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

Similar topics

8
3218
by: Shawn Casey | last post by:
Consider the following code: interface IBase { virtual void BaseFunction() = 0; }; interface IDerived : public IBase { virtual void DerivedFunction() = 0;
8
2433
by: Shaun C Farrugia | last post by:
I have a multi team solution being built where teams are segmented off into seperate projects. One project is an over all framework containing a Broker class responsible for instantiating different subclasses of type Connector - the class only contains the abstract Connector class and the Broker. A seperate project contains the actual subclasses of the Connector that are database specific. Another team will work exclusivley in that...
17
2351
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component oriented design (owreilly - Juval Lowy), and it was actually very nice. The book goes on about how we should use Interfaces exposure instead of classes (this is my terminology and english is not my language so I hope you understand what I'm on about...).
14
339
by: Daniel Billingsley | last post by:
Can someone please comment if there's something wrong from an OO point of view with the model represented by the following code snippet. I hope it's fairly obvious what the point is of the code I haven't explicitly included. For purposes of this discussion let's say that classes derived from SomeBaseClass my implement any combination of several interfaces. Therefore, I'm not crazy about having a bunch of derived classes with all...
7
1587
by: Ant | last post by:
Hi, I’m wondering what practical use is there for creating interfaces. I can fully appreciate creating an abstract class for the purpose of inheriting, but why an interface? Is it just to promote polymorphism while keeping implementation unique? I dunno; I know I must be missing something big here. Any clues would, as always, be greatly appreciated. Thank you Ant
9
5199
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
8
1451
by: ^MisterJingo^ | last post by:
Hi all, I have a question regarding inheritance. I'll use the following code for an example (its been stripped down to the minimum): // code start using System; class Animal {
7
4470
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears to be checking that the correct data type is used DataAcess sets an abstract class and methods
1
1721
by: Larry | last post by:
I checked definition of class CollectionBase public abstract class CollectionBase : IList, ICollection, IEnumerable, it implements 3 interface IList, ICollection and IEnumerable. I found IList is derived or extended from ICollection and IEnumerable. Why the definition of class CollectionBase just implement IList interface which has functions of ICollection and IEnumerable?
0
8823
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8719
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9348
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9109
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6648
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5970
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3177
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.