473,320 Members | 2,020 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.

Why no public qualified interface implementations?

Can anyone explain why a interface method implementation using the fully
qualified name cannot be public or protected? Sample below:

public interface IDrawable
{
void DrawYourself();
}
public interface IPositional
{
Point Position
{
get;
set;
}
}
public interface IShape : IDrawable, IPositional {}
public abstract class AbstractShape : IShape
{
Point position= new Point(0,0);
public virtual void DrawYourself()
{
System.Console.WriteLine("Abstract Shape");
}
// This cannot be public or protected
Point IPositional.Position
{
get {return position;}
set {position= value;}
}
// This works as expected in subclass
public Point Position
{
get {return position;}
set {position= value;}
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 1411
Interfaces are assumed public which is why you can't supply your own access
modifier. Think about it, what good is a non-public function on an
interface?

"Jeff Louie" <je********@yahoo.com> wrote in message
news:ej******************@TK2MSFTNGP09.phx.gbl...
Can anyone explain why a interface method implementation using the fully
qualified name cannot be public or protected? Sample below:

public interface IDrawable
{
void DrawYourself();
}
public interface IPositional
{
Point Position
{
get;
set;
}
}
public interface IShape : IDrawable, IPositional {}
public abstract class AbstractShape : IShape
{
Point position= new Point(0,0);
public virtual void DrawYourself()
{
System.Console.WriteLine("Abstract Shape");
}
// This cannot be public or protected
Point IPositional.Position
{
get {return position;}
set {position= value;}
}
// This works as expected in subclass
public Point Position
{
get {return position;}
set {position= value;}
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Interface members are public. You cannot implement the members with a
different access modifier.

"Jeff Louie" wrote:
Can anyone explain why a interface method implementation using the fully
qualified name cannot be public or protected? Sample below:

public interface IDrawable
{
void DrawYourself();
}
public interface IPositional
{
Point Position
{
get;
set;
}
}
public interface IShape : IDrawable, IPositional {}
public abstract class AbstractShape : IShape
{
Point position= new Point(0,0);
public virtual void DrawYourself()
{
System.Console.WriteLine("Abstract Shape");
}
// This cannot be public or protected
Point IPositional.Position
{
get {return position;}
set {position= value;}
}
// This works as expected in subclass
public Point Position
{
get {return position;}
set {position= value;}
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
Adrian and Rakesh.... So I assumed, but every time I try to subclass
AbstractShape using fully qualified names I find that an implementation
of a
method or property with a fully qualified name is _not_ touchable from
within
the subclass.

Regards,
Jeff
Interfaces are assumed public which is why you can't supply your own

access modifier. Think about it, what good is a non-public function on
an
interface?<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Jeff Louie <je********@yahoo.com> wrote:
Adrian and Rakesh.... So I assumed, but every time I try to subclass
AbstractShape using fully qualified names I find that an
implementation of a method or property with a fully qualified name is
_not_ touchable from within the subclass.


It is - but only if you cast it to the interface first.

From the C# spec:

<quote>
Explicit interface member implementations have different accessibility
characteristics than other members. Because explicit interface member
implementations are never accessible through their fully qualified name
in a method invocation or a property access, they are in a sense
private. However, since they can be accessed through an interface
instance, they are in a sense also public.
</quote>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hi Jon... Thanks for the clarification. This had me quite befuddled.

Regards,
Jeff

<quote>
Explicit interface member implementations have different accessibility
characteristics than other members. Because explicit interface member
implementations are never accessible through their fully qualified name
in a method invocation or a property access, they are in a sense
private. However, since they can be accessed through an interface
instance, they are in a sense also public.
</quote>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

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

Similar topics

175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
by: Mark | last post by:
Below I've created an interface ... why do all implementations of the methods have to be public? What if I want them to be private or protected? public interface IOisWebPageStandard { void...
7
by: Hazz | last post by:
Are there any good references/articles/books which provide clarity toward my insecurity still on deciding how to model a complex system? I still feel uncomfortable with my understanding, even...
3
by: Joe Fromm | last post by:
Perhaps I'm missing something obvious, but I've been curious about one of the coding practices I see advocated. I'm a longtime C/C++ programmer trying to learn C#, and I started looking around for...
10
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
6
by: Ricky W. Hunt | last post by:
It's dawning on my a lot of my problems with VB.NET is I'm still approaching it in the same way I've programmed since the late 70's. I've always been very structured, flow-charted everything, used...
2
by: Burak | last post by:
Hello, I have a web service that has a two user defined public classes. For sake of brevity, I'll write them as follows Public Class Service1 Public Class Class1 Public x as integer End...
20
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: 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.