473,597 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling explicity interface implementation from a subclass

Could someone tell me if it's possible (and if so, how) to call an
explicitly-implemented interface method from a subclass? I have a class in
which I have to explicity implement some methods, but my subclasses, which
should use them, cannot call them. I'm not sure if it just isn't possible
due to visibility or if I just don't have the syntax right. I can't make
the methods protected, as the compiler complains (although the documentation
for the error only says it's true of the "public" accessor, "protected" also
doesn't work, but when they use the default accessor, I can't get the
compiler to see the methods.
Nov 16 '05 #1
5 2433
Keith,

I am curious, since it is an interface implementation, why not just cast
the "this" pointer to the interface and make the call? Or do you mean you
want to call the base implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message
news:eU******** ********@TK2MSF TNGP12.phx.gbl. ..
Could someone tell me if it's possible (and if so, how) to call an
explicitly-implemented interface method from a subclass? I have a class in which I have to explicity implement some methods, but my subclasses, which
should use them, cannot call them. I'm not sure if it just isn't possible
due to visibility or if I just don't have the syntax right. I can't make
the methods protected, as the compiler complains (although the documentation for the error only says it's true of the "public" accessor, "protected" also doesn't work, but when they use the default accessor, I can't get the
compiler to see the methods.

Nov 16 '05 #2
Hmmm...I tried this morning, but couldn't get it to work, but now it *is*
compiling (I hadn't dosed up with caffeine yet, so I could have been missing
something obvious). One major issue I am having that could have played a
role is that due to my hierarchy, I am having to do some delayed iface
implementations in subclasses (IDictionary.Ge tEnumerator vs.
IEnumerable.Get Enumerator is the primary culprit). Because I don't
implement ICollection at the base level, I am doing a lot of weird
implementations of my various methods. I'm going to rewrite my base classes
from scratch to get a cleaner look at my methods, and if things still aren't
working, I'll post actual code (right now, my code is too verbose to really
be postable within the context of this thread).

Thanks for the help!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uY******** ******@tk2msftn gp13.phx.gbl...
Keith,

I am curious, since it is an interface implementation, why not just cast the "this" pointer to the interface and make the call? Or do you mean you
want to call the base implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message
news:eU******** ********@TK2MSF TNGP12.phx.gbl. ..
Could someone tell me if it's possible (and if so, how) to call an
explicitly-implemented interface method from a subclass? I have a class

in
which I have to explicity implement some methods, but my subclasses, which should use them, cannot call them. I'm not sure if it just isn't possible due to visibility or if I just don't have the syntax right. I can't make the methods protected, as the compiler complains (although the

documentation
for the error only says it's true of the "public" accessor, "protected"

also
doesn't work, but when they use the default accessor, I can't get the
compiler to see the methods.


Nov 16 '05 #3
Here's a problem I'd forgotten about that further complicates things: My
hierarchy is like so:
abstract class EventfulCollect ion: ICollection
abstract class EventfulListCol lection: IList (note to MS: FXCop flags
"EventfulLI st" as wrong because it implements ICollection and should
therefore end in "Collection ". Why does FXCop not realize that it actually
implements the subinterface IList and let me name the thing IList? .Net
itself breaks this rule with ArrayList!)

The problem this causes is that I must declare ICollection.Cop yTo(...), but
I don't want to implement the methods here, allowing my subclasses (some are
ILists, others are IDictionaries) to implement it themselves (and it isn't
just this method or this interface). So I can't say:
protected abstract CopyTo(...);

but I don't want to say:
ICollection.Cop yTo(...) {...} because then I'm implementing code that I
don't want to implement here (EventfulCollec tion has no private collection,
deferring that until the subclasses, so I have to implement it as a no-op,
which I HATE doing in OO). I want EventfulCollect ion to satisfy ICollection
responsibilitie s at an absolute minimum so that actual implementation occurs
in the subclasses. However, I still need to hide the implementations such
that my type-specific collections have their own implementations that are
overridden versions of the parent methods.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uY******** ******@tk2msftn gp13.phx.gbl...
Keith,

I am curious, since it is an interface implementation, why not just cast the "this" pointer to the interface and make the call? Or do you mean you
want to call the base implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message
news:eU******** ********@TK2MSF TNGP12.phx.gbl. ..
Could someone tell me if it's possible (and if so, how) to call an
explicitly-implemented interface method from a subclass? I have a class

in
which I have to explicity implement some methods, but my subclasses, which should use them, cannot call them. I'm not sure if it just isn't possible due to visibility or if I just don't have the syntax right. I can't make the methods protected, as the compiler complains (although the

documentation
for the error only says it's true of the "public" accessor, "protected"

also
doesn't work, but when they use the default accessor, I can't get the
compiler to see the methods.


Nov 16 '05 #4
Keith,

I've had this problem as well. I think that the best way to get around
it (although the most tedious) is to have abstract methods on the base class
which the implementation of the interface calls. Then, your sub classes
would just override the abstract methods, and you shouldn't have a problem
then.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message
news:eS******** ******@TK2MSFTN GP12.phx.gbl...
Here's a problem I'd forgotten about that further complicates things: My
hierarchy is like so:
abstract class EventfulCollect ion: ICollection
abstract class EventfulListCol lection: IList (note to MS: FXCop flags
"EventfulLI st" as wrong because it implements ICollection and should
therefore end in "Collection ". Why does FXCop not realize that it actually implements the subinterface IList and let me name the thing IList? .Net
itself breaks this rule with ArrayList!)

The problem this causes is that I must declare ICollection.Cop yTo(...), but I don't want to implement the methods here, allowing my subclasses (some are ILists, others are IDictionaries) to implement it themselves (and it isn't
just this method or this interface). So I can't say:
protected abstract CopyTo(...);

but I don't want to say:
ICollection.Cop yTo(...) {...} because then I'm implementing code that I
don't want to implement here (EventfulCollec tion has no private collection, deferring that until the subclasses, so I have to implement it as a no-op,
which I HATE doing in OO). I want EventfulCollect ion to satisfy ICollection responsibilitie s at an absolute minimum so that actual implementation occurs in the subclasses. However, I still need to hide the implementations such
that my type-specific collections have their own implementations that are
overridden versions of the parent methods.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:uY******** ******@tk2msftn gp13.phx.gbl...
Keith,

I am curious, since it is an interface implementation, why not just

cast
the "this" pointer to the interface and make the call? Or do you mean you
want to call the base implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message news:eU******** ********@TK2MSF TNGP12.phx.gbl. ..
Could someone tell me if it's possible (and if so, how) to call an
explicitly-implemented interface method from a subclass? I have a
class in
which I have to explicity implement some methods, but my subclasses, which should use them, cannot call them. I'm not sure if it just isn't possible due to visibility or if I just don't have the syntax right. I can't make the methods protected, as the compiler complains (although the

documentation
for the error only says it's true of the "public" accessor,

"protected" also
doesn't work, but when they use the default accessor, I can't get the
compiler to see the methods.



Nov 16 '05 #5
The difficulty there (and I don't know if this is really the fault of the
language or the design of the hierarchy) is that I can't expose
IEnumerable.Get Enumerator() because my dictionary-based implementation has
to expose it as IDictionary.Get Enumerator(), which has a different return
type, so the dictionary version cannot expose both methods (unless one is an
explicity definition, which means I have to implement what should be
abstract)
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:OR******** *****@TK2MSFTNG P10.phx.gbl...
Keith,

I've had this problem as well. I think that the best way to get around it (although the most tedious) is to have abstract methods on the base class which the implementation of the interface calls. Then, your sub classes
would just override the abstract methods, and you shouldn't have a problem
then.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message
news:eS******** ******@TK2MSFTN GP12.phx.gbl...
Here's a problem I'd forgotten about that further complicates things: My
hierarchy is like so:
abstract class EventfulCollect ion: ICollection
abstract class EventfulListCol lection: IList (note to MS: FXCop flags
"EventfulLI st" as wrong because it implements ICollection and should
therefore end in "Collection ". Why does FXCop not realize that it

actually
implements the subinterface IList and let me name the thing IList? .Net
itself breaks this rule with ArrayList!)

The problem this causes is that I must declare ICollection.Cop yTo(...),

but
I don't want to implement the methods here, allowing my subclasses (some

are
ILists, others are IDictionaries) to implement it themselves (and it isn't just this method or this interface). So I can't say:
protected abstract CopyTo(...);

but I don't want to say:
ICollection.Cop yTo(...) {...} because then I'm implementing code that I
don't want to implement here (EventfulCollec tion has no private

collection,
deferring that until the subclasses, so I have to implement it as a no-op, which I HATE doing in OO). I want EventfulCollect ion to satisfy

ICollection
responsibilitie s at an absolute minimum so that actual implementation

occurs
in the subclasses. However, I still need to hide the implementations such that my type-specific collections have their own implementations that are overridden versions of the parent methods.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote

in
message news:uY******** ******@tk2msftn gp13.phx.gbl...
Keith,

I am curious, since it is an interface implementation, why not just
cast
the "this" pointer to the interface and make the call? Or do you mean

you want to call the base implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith Patrick" <ri************ *******@nospamh otmail.com> wrote in message news:eU******** ********@TK2MSF TNGP12.phx.gbl. ..
> Could someone tell me if it's possible (and if so, how) to call an
> explicitly-implemented interface method from a subclass? I have a class in
> which I have to explicity implement some methods, but my subclasses,

which
> should use them, cannot call them. I'm not sure if it just isn't

possible
> due to visibility or if I just don't have the syntax right. I can't

make
> the methods protected, as the compiler complains (although the
documentation
> for the error only says it's true of the "public" accessor, "protected" also
> doesn't work, but when they use the default accessor, I can't get

the > compiler to see the methods.
>
>



Nov 16 '05 #6

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

Similar topics

5
1421
by: Jeff Louie | last post by:
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
9
7546
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must be implemented. So if you have a class which inherits base class that inherts an interface, then your classes will have a standard. I suppose you can also check for interface at run time say when dll is loaded and see if it implememts whats...
11
1725
by: David Thielen | last post by:
Hi; I am writing a class that implements IDbConnection. The i/f defines a method BeginTransaction() that returns an IDbTransaction. I want to define this as returning a DbTransaction (as DbConnection does). It makes sense to me that this is legal as DbTransaction implements IDbTransaction so it does meet the contract of returning an IDbTransaction. But it won't compile - how do I get this to work? There must be a way as DbConnection...
12
2276
by: Ramon | last post by:
Hello I'm new to OOP in PHP and I have this question: I have a class called "Form", which contains a collection of classes (objects) called "Textbox". Now I need to call the Textbox class's method "getOuterHTML()". In Visual Basic, you should do it like this: oForm.getTextBoxByID("Number").getOuterHTML()
6
1766
by: Dave Booker | last post by:
I want to do something like this: public class Animal; public interface IZoo { List<Animal> Animals { get; } void Feed(Animal a); }
3
2002
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. Basically, all of the inherited classes deal with data in some way or another. I need to make sure that when the data is changed on any of those classes, they raise an event called "DataChanged", and have that enforced in some way from the abstract...
4
2788
by: gabriel | last post by:
Hi Firstly i'd like to thank you for reading this and offer my appreciation for replies in advance. I've recently been writing a program which implements a user-defined API (Robocode to be exact). I, however, need to create my own implementation of an interface in order to perform some arbitary function. My question is, how would i go about creating my own instance of this
20
2851
by: Jorgen Bodde | last post by:
Hi All, Now that I am really diving into Python, I encounter a lot of things that us newbies find difficult to get right. I thought I understood how super() worked, but with 'private' members it does not seem to work. For example; .... def __baseMethod(self): .... print 'Test'
47
4923
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2...
0
8380
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
8024
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
8258
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
6681
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 project—planning, coding, testing, and deployment—without 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...
1
5844
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
5423
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
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2394
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 we have to send another system
1
1493
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.