472,373 Members | 1,965 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,373 software developers and data experts.

Explicit Interface Implementation purpose

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,
implementation. Also, if you implement more than two interfaces with
the same method, which is rarity in practice or so it seems. To me
it appears a shallow end... Am I missing something?
Thanks
Oct 15 '08 #1
2 1826
Some interfaces are not intended for the programmer to call, or would
add clutter most of the time (called rarely). For example, ITypedList/
IBindingList/ICustomTypeDescriptor are examples from
System.ComponentModel that are intended for use by TypeDescriptor
(etc). You wouldn't call these methods directly, so why have them on
the API?

Sometimes explicit implementation is used to provide a more meaningful
public API - for example:

public Foo Clone() { ... } // always actually returns a Foo
object ICloneable.Clone() { return Clone(); }

The same is true of the non-generic IList etc.

And sometimes you need to do this because 2 interfaces have
conflicting methods, or the *interface* meaning of SomeMethod(), and
the class's *local* meaning of SomeMethod(), are slightly different.
IEnumerable<T>.GetEnumerator() is an example of the first.

Marc
Oct 15 '08 #2
If an implementation is virtual and a base object has been derived several
times by others it can be hard to figure out exactly where the call goes.
With an explicit implementation the call always hits the call in the base
class - makes it easier to debug.

This approach has saved me a load of time with remoted calls.

ie.

interface I
{
void MyCall();
}

Derived6: Derived5
{
}

Derived5:Derived4
{
override void MyCall()
{
// Do stuff
base.MyCall();
}
}

Derived1:Base
{
override void MyCall()
{
// Do stuff
}
}

....

Base : I
{
virtual void MyCall()
{
}

I.MyCall()
{
// Always gets trapped here
this.MyCall(); // If you just called MyCall without explicit
implementation you'd have to hunt through every class that derives from Base
to find where a call to MyCall actually ends up.
}
}

Cheers,

Adam.

"puzzlecracker" <ir*********@gmail.comwrote in message
news:36**********************************@d10g2000 pra.googlegroups.com...
>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,
implementation. Also, if you implement more than two interfaces with
the same method, which is rarity in practice or so it seems. To me
it appears a shallow end... Am I missing something?
Thanks

Oct 15 '08 #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...
2
by: COLIN JACK | last post by:
Hi All, I've got a situation where I'm implementing an interface (BaseInterface in example below) and I want to use explicity interface implementation of an event so that I can add type safety. ...
4
by: Mathieu Cartoixa | last post by:
Hi, I have been annoyed in one of my recent projects with a problem related to the explicit implementation of an interface on a value type. I will take an example to show the problem. Say we...
14
by: Noone | last post by:
Hello all, Ok, I want to create a program that will load plugins (dll's) from a plugin folder. I can create the forms and put them into a dll but I cannot actually add them dynamically at run...
0
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application)....
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
0
by: Brandon Driesen | last post by:
The following illustrates my question. Why is it when I bind to an a collection of items whose interface implementation is explicit, there is an error during the binding process wherein the error...
1
by: recherche | last post by:
Hola! I tried the following public implementation of interface indexer by struct (Code Snippet 1) in private and explicit implementation by struct (Code Snippet 2) but in vain. Please help! ...
1
by: =?Utf-8?B?Sk0=?= | last post by:
In an application I have an interface with methods and properties. The interface is used on a Class (ie class MyClass : IMyClassA, IMyClassB). On a windows form I define a BindingSource...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.