473,786 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Abst ract Shape");
}
// This cannot be public or protected
Point IPositional.Pos ition
{
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 1429
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********@yah oo.com> wrote in message
news:ej******** **********@TK2M SFTNGP09.phx.gb l...
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("Abst ract Shape");
}
// This cannot be public or protected
Point IPositional.Pos ition
{
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("Abst ract Shape");
}
// This cannot be public or protected
Point IPositional.Pos ition
{
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********@yah oo.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.co m>
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
8909
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 changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
5
9794
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 SomeMethod1(); void SomeMethod2(); void SomeMethod3(); }
7
12877
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 though I have worked with these systems on when to decide to use interfaces (and how they should be developed) as opposed to or complemented by the use of inheritance from base classes. If I am thinking from the point of view of some specific activity...
3
10888
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 coding standards/best practices. Several of the documents I've read require that all members be private (or protected), and the get/set properties be provided for any elements exposed to the outside world. In C++ this makes perfect sense,...
10
2981
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 class. The interface has implied abstract methods/properties and derived classes can inherit multiple interfaces. The interface properties/methods have no implementation. Besides definitions of the two, what are some conceptual reasons to use...
18
3785
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
1945
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 subroutines, etc. Now I'm trying to study this new way and I'm getting some terms confused and can find no clear definition (some even overlap or use two different words for the same thing, even when they are actually different). I'm reading a...
2
4219
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 Class
20
6089
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, as we seem to lack only a single 'step' to have "full separation"... We have a first project, namespace Ninterface, that contains the interface definitions in class1_interface.cs, like this: namespace Ninterface { public interface IClass1{
0
9647
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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
10104
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
9959
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...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.