473,493 Members | 4,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1898
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
2751
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
2502
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
2361
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
4043
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
2196
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
2766
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
1229
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
2742
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
3195
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...
0
7118
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,...
0
6980
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...
1
6862
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...
0
7364
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...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
4886
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
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 ...
1
637
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.