473,831 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interface Name Collisions

Hey,

I was trying some code with the .Net framework 1.1, and I found that the
Interface name collisions is still not resolved in that version of the .net
framework.
I am refering to that piece of code which i took from the book of Inside C#
(Archer).

using System;

interface ISerializable
{
void SaveData();
}

interface IDataStore
{
void SaveData();
}

class Test : ISerializable, IDataStore
{
public void SaveData()
{
Console.WriteLi ne("Test.SaveDa ta called");
}
}

class NameCollisions1 App
{
public static void Main()
{
Test test = new Test();

Console.WriteLi ne("Calling Test.SaveData() ");
test.SaveData() ;
}
}

the code is still compiling, although logically it shouldn't.
So My question is Why this is not resolved ?
and is there an apparent benefit from this capability that i am not aware
of?

regards
Nov 15 '05 #1
6 1991
Hi Walid,

If explicit interfaces are not used, the same SaveData()
implementation is used for both the interfaces. I think this feature
is in place in order to get a default implementation
to service both the interfaces - This can be used when
ISerializable.S aveData() and IDataStore.Save Data() intend to represent
the same semantics.

If teh SaveData for each of the interfaces intend to convey different
semantics,
you may like to actually use explicit interfaces to define
separate implementations for each of the SaveData() methods.

class Test : ISerializable, IDataStore
{
void ISerialzable.Sa veData()
{
// Implement ISerializable.S aveData
}
void IDataStore.Save Data()
{
// Implement IDataStore.Save Data
}

}

Regards,
Aravind C
"Walid" <wk*******@hotm ail.com> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...
Hey,

I was trying some code with the .Net framework 1.1, and I found that the
Interface name collisions is still not resolved in that version of the ..net framework.
I am refering to that piece of code which i took from the book of Inside C# (Archer).

using System;

interface ISerializable
{
void SaveData();
}

interface IDataStore
{
void SaveData();
}

class Test : ISerializable, IDataStore
{
public void SaveData()
{
Console.WriteLi ne("Test.SaveDa ta called");
}
}

class NameCollisions1 App
{
public static void Main()
{
Test test = new Test();

Console.WriteLi ne("Calling Test.SaveData() ");
test.SaveData() ;
}
}

the code is still compiling, although logically it shouldn't.
So My question is Why this is not resolved ?
and is there an apparent benefit from this capability that i am not aware
of?

regards

Nov 15 '05 #2
Hi Aravind C,

Thnx But why this is allowed to compile ?
(refering to the non referenced method name)
shouldn't be a compile error?
regards
"Aravind C" <ar***********@ nospam.hotmail. com> wrote in message
news:eW******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Walid,

If explicit interfaces are not used, the same SaveData()
implementation is used for both the interfaces. I think this feature
is in place in order to get a default implementation
to service both the interfaces - This can be used when
ISerializable.S aveData() and IDataStore.Save Data() intend to represent
the same semantics.

If teh SaveData for each of the interfaces intend to convey different
semantics,
you may like to actually use explicit interfaces to define
separate implementations for each of the SaveData() methods.

class Test : ISerializable, IDataStore
{
void ISerialzable.Sa veData()
{
// Implement ISerializable.S aveData
}
void IDataStore.Save Data()
{
// Implement IDataStore.Save Data
}

}

Regards,
Aravind C
"Walid" <wk*******@hotm ail.com> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...
Hey,

I was trying some code with the .Net framework 1.1, and I found that the
Interface name collisions is still not resolved in that version of the

.net
framework.
I am refering to that piece of code which i took from the book of Inside

C#
(Archer).

using System;

interface ISerializable
{
void SaveData();
}

interface IDataStore
{
void SaveData();
}

class Test : ISerializable, IDataStore
{
public void SaveData()
{
Console.WriteLi ne("Test.SaveDa ta called");
}
}

class NameCollisions1 App
{
public static void Main()
{
Test test = new Test();

Console.WriteLi ne("Calling Test.SaveData() ");
test.SaveData() ;
}
}

the code is still compiling, although logically it shouldn't.
So My question is Why this is not resolved ?
and is there an apparent benefit from this capability that i am not aware of?

regards


Nov 15 '05 #3
Walid <wk*******@hotm ail.com> wrote:
Thnx But why this is allowed to compile ?
(refering to the non referenced method name)
shouldn't be a compile error?


No. In some cases it may be exactly what you want. Is there something
in the spec which makes you think it *should* be a compile error?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
How can be exactly what the client wants since he doesn't know which method
has been called?

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Walid <wk*******@hotm ail.com> wrote:
Thnx But why this is allowed to compile ?
(refering to the non referenced method name)
shouldn't be a compile error?


No. In some cases it may be exactly what you want. Is there something
in the spec which makes you think it *should* be a compile error?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5

"Walid" <wk*******@hotm ail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
How can be exactly what the client wants since he doesn't know which method has been called?
Casting.
The client should, if it is concerned with which version of the method is
called, cast to the right interface.
using IDataStore, ISerializable like the earlier examples were:

class Class : IDataStore, ISerializable
{
public void SaveData()
{

}

void IDataStore.Save Data()
{

}

void ISerializable.S aveData()
{
}
}
IDataStore isd = (IDataStore)Cla ss;
ISerializable iserial = ISerializable(C lass);

ids.SaveData() // calls IDataStore.Save ()
iserial.SavData () // calls ISerializable.S ave();
Class.SaveData( ) // calls the public method save data, be it an interface
method or just a plain public method. "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Walid <wk*******@hotm ail.com> wrote:
Thnx But why this is allowed to compile ?
(refering to the non referenced method name)
shouldn't be a compile error?


No. In some cases it may be exactly what you want. Is there something
in the spec which makes you think it *should* be a compile error?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #6
Walid <wk*******@hotm ail.com> wrote:
How can be exactly what the client wants since he doesn't know which method
has been called?


If there's only one method, and that method satisfies the contract of
the interface, then why would he care? Why should someone have to
specify two methods which do the same thing, just to satisfy two
different interfaces which use the same method name?

Only if the interface names clash *and* the semantics of the interfaces
require different implementations is there a problem, which is
"solved" by explicit interface implementation. (Personally I'm not a
fan of EII in the first place, but there we go. I can see how it's
useful for solving this rare problem, but it seems it's often used when
it doesn't need to be.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7

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

Similar topics

2
2133
by: John | last post by:
Hi, I have a data driven application which has some generalized components. So, for reuse, I am building the components so they can be reused in other projects ... it takes almost no extra effort, just a bit of planning. Following the security convention of only giving the user as much access as required, I always create at least 2 users for each app; owner & user. And recently I've had a cool idea for handling multiple sites with...
2
2222
by: Vam | last post by:
my compiler doesn't compile the following: struct Base1 { virtual void F(){} }; struct Base2 { virtual void F(){}
6
3949
by: Peter Ammon | last post by:
Let's say I need to swap two int values frequently. I would write a macro: #define swap(int a, int b) \ do { \ int temp = (a); \ (a) = (b); \ (b) = temp; \ } while (0)
12
2813
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 you are implementing in the class. Other than to resolve the problem that arises when a class implements two interfaces with the same method signature, what good is it?
5
10381
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
6
1596
by: jason | last post by:
I found the below example online, while trying to under Interfaces. In layman's terms, can somebody explain what the purpose of this line is: void SportCharacteristics(); //LOCATED IN THE Iball interface. ... I read its a method without an implemetnation.. like an abstract I think.. so how does it serve this project?
15
2813
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. For example: f(3) f(3, )
2
1802
by: Tyno Gendo | last post by:
I'm writing a test "modular site". So far I have created an App class, a Module Manager class and a couple of test modules. The Manager looks in a directory called 'modules' and then for every ..php file is try to create a class of type <filenameminus the .php, so eg. for testmodule.php it tries to create a class "testmodule" and puts it into an array within the module manager called $_modules Module Manager has a dispatch_message...
5
2540
by: Markus Dehmann | last post by:
Do I have to handle hash collisions in a hash_set myself? I did a test in which I use find() to look for objects in a hash_set. These objects are definitely not contained, but find() sometimes finds them anyway. See this code: <code> #include <iostream> #include <stdexcept> #include <ctime>
0
9794
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10496
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10538
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,...
0
10210
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
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
5622
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.