Re: Calling explicity interface implementation from a subclass

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 05/17/04


Date: Mon, 17 May 2004 14:39:54 -0400

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]
               - mvp@spam.guard.caspershouse.com
"Keith Patrick" <richard_keith_patrick@nospamhotmail.com> wrote in message
news:eSSkKJCPEHA.1340@TK2MSFTNGP12.phx.gbl...
> Here's a problem I'd forgotten about that further complicates things:  My
> hierarchy is like so:
> abstract class EventfulCollection: ICollection
> abstract class EventfulListCollection: IList (note to MS: FXCop flags
> "EventfulLIst" 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.CopyTo(...),
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.CopyTo(...) {...} because then I'm implementing code that I
> don't want to implement here (EventfulCollection 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 EventfulCollection to satisfy
ICollection
> responsibilities 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]" <mvp@spam.guard.caspershouse.com> wrote
in
> message news:uYQ5R4APEHA.3016@tk2msftngp13.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]
> >                - mvp@spam.guard.caspershouse.com
> >
> > "Keith Patrick" <richard_keith_patrick@nospamhotmail.com> wrote in
message
> > news:eU%23QF2APEHA.2996@TK2MSFTNGP12.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.
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Calling explicity interface implementation from a subclass
    ... abstract class EventfulCollection: ICollection ... "EventfulLIst" as wrong because it implements ICollection and should ... 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 ...
    (microsoft.public.dotnet.languages.csharp)
  • 7.0 wishlist?
    ... Any object can be used where an interface type is expected if it has the right set of method signatures, whether or not it "implements" the interface using that keyword. ... the algorithm name is hard-coded and so this exception ... Most invocations of runnables ... Allow subclassing an enum with the subclasses able to REMOVE (not ...
    (comp.lang.java.programmer)
  • Re: bloated base class?
    ... Now the app needs to be extended to process a ... > interface depending on what kind of data they work with. ... you need different Process subclasses as well. ... but that is isolated to whoever instantiates the relationships ...
    (comp.object)
  • Re: How can I make this design tidier?
    ... Interface "AnyElement" with about 80 properties. ... A generalization with 60 sibling subclasses is almost surely wrong because it is too big. ... If so, then they don't share that property with other superclass members in other subclasses, which defeats one goal of generalization. ...
    (comp.object)
  • Re: Classes and interfaces
    ... > I want to create a Shape class and some subclasses such as Rectangle, ... > to implement a Draw() function. ... Interface is a mechanism for communication between two parties. ...
    (comp.lang.cpp)