473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Explicit Interfaces and overriding methods

I know that I can't declare a method in an interface as virtual and override
it, when I am using an explicit interface, but I am wondering if anyone else
has come across this problem and how they handled it? I would definately
prefer to use explicit interfaces, but I also know I shouldn't mix and match
explicit versus implicit interfaces and don't seem to have a choice here?

Any thoughts on this?
May 22 '07 #1
2 1983
What I have done is create virtual methods which the explicit interface
definitions just pass the parameters and return values between, for example:

public interface IMyInterface
{
string Op(string param);
}

public class MyClass : IMyInterface
{
string IMyInterface.Op(string param)
{
// Just call the internal method.
return InternalOp(param);
}

protected virtual string InternalOp(string param)
{
// Do work here.
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"wdudek" <wd****@newsgroup.nospamwrote in message
news:F2**********************************@microsof t.com...
>I know that I can't declare a method in an interface as virtual and
override
it, when I am using an explicit interface, but I am wondering if anyone
else
has come across this problem and how they handled it? I would definately
prefer to use explicit interfaces, but I also know I shouldn't mix and
match
explicit versus implicit interfaces and don't seem to have a choice here?

Any thoughts on this?

May 22 '07 #2
Thanks, that is exactly what I needed!

"Nicholas Paldino [.NET/C# MVP]" wrote:
What I have done is create virtual methods which the explicit interface
definitions just pass the parameters and return values between, for example:

public interface IMyInterface
{
string Op(string param);
}

public class MyClass : IMyInterface
{
string IMyInterface.Op(string param)
{
// Just call the internal method.
return InternalOp(param);
}

protected virtual string InternalOp(string param)
{
// Do work here.
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"wdudek" <wd****@newsgroup.nospamwrote in message
news:F2**********************************@microsof t.com...
I know that I can't declare a method in an interface as virtual and
override
it, when I am using an explicit interface, but I am wondering if anyone
else
has come across this problem and how they handled it? I would definately
prefer to use explicit interfaces, but I also know I shouldn't mix and
match
explicit versus implicit interfaces and don't seem to have a choice here?

Any thoughts on this?


May 22 '07 #3

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

Similar topics

12
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
10
by: Michael Grimsley | last post by:
I have been looking at interfaces in C# and cannot seem to understand them. I am told that interfaces resembles a class with no code and that methods declared in an interface are not allowed to...
30
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
0
by: Peter Insley via .NET 247 | last post by:
Hi, have been searching for an answer for this for quite a while,I would be greatfull for any help. We are developing a codebase that of components that we wouldlike to be able to write in MC++ or...
7
by: Raterus | last post by:
I've got a good question about object-oriented programming, I hope I can explain it well enough. I'm creating a UserManager, which I'm going to inherit from so different applications can share...
4
by: Morten Lemvigh | last post by:
I'm trying to make something like a Java interface. I have a class, that needs a distance measure. The distance measure is itself a class passed to the constructor: MyClass::MyClass(vector v,...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
2
by: puzzlecracker | last post by:
I don't see the purpose of explicit interface implementation other than to hide its signature in the class that implements it, and, instead, write your own, perhaps with a different signature,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.