Mike,

I think the thing you might be missing is the "virtual" key word on your
methods.  That's what corresponds to "Overridable" in VB.  In C# and VB,
methods aren't virtual by default (one thing Java got right, IMHO)

If you don't add that then any child classes that had a Remove() method
would simply hide the base version.  And AFIK, the new Remove() wouldn't be
part of the interface.

So, I think the following will work (I haven't tried it) and will do what
you want.

   protected internal interface IBusiness {
       void Remove();
       void Save();
       Guid ID { get; set;}
   }


   protected abstract class T: IBusiness {

       protected virtual void Remove() {
           throw new Exception("The method or operation is not
implemented.");
       }

       protected virtual void Save() {
           throw new Exception("The method or operation is not
implemented.");
       }

       protected virtual Guid ID {
           get {
               throw new Exception("The method or operation is not
implemented.");
           }
           set {
               throw new Exception("The method or operation is not
implemented.");
           }
       }
   }

   protected internal class X: T {

       protected virtual void Remove() {
           //Do something here

       }
       // inherits Save() and ID
   }



   public static void Main() {
      IBusiness i = new X();
      i.Remove();
   }


HTH.

______________________________
- David Lanouette
- [EMAIL PROTECTED]

"Excellence, then, is not an act, but a habit" - Aristotle





> -----Original Message-----
> From: Discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
> Sent: Friday, July 07, 2006 4:42 PM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Implementing an Interface - C#
> vs. VB.NET
>
> I'm guessing that VB does something similar behind the scenes
> when compiling to IL.
> Otherwise it doesn't make any sense that VB allows such a
> construct but C# does not.
>
> In VB6, your interface definitions always had to be private
> (it's been a while since I've done anything with VB6) and
> always accessed via the interface; that is similar to the
> explicit implementation of the interface in C#.
>
>
> On 7/7/06, gregory young <[EMAIL PROTECTED]> wrote:
> >
> > If the interface isnt public then the explicit
> implementation's only
> > difference is the need to go through the interface as
> opposed to the
> > object.
> > If you really want internal methods on your object as well
> .. (I would
> > recommend using the interface instead but it seems to be your goal)
> >
> >
> >    class FooBase :IFoo {
> >        virtual internal void internalbar() {
> >            Console.WriteLine("FooBase");
> >        }
> >        void IFoo.Bar() {
> >            this.internalbar();
> >        }
> >    }
> >
> >    class FooDerived : FooBase, IFoo {
> >        internal override void internalbar() {
> >            Console.WriteLine("DerivedFoo");
> >        }
> >    }
> >
> > Will provide that for you ... This should exactly duplicate
> the method
> > your VB code was working .. You can continue to override the
> > functionality in derived classes for both the internal and for the
> > interface method (you could even implement them seperately by
> > reimplementing the interface.
> >
> >
> >
> > On 7/7/06, Mike Andrews <[EMAIL PROTECTED]> wrote:
> > >
> > > It shouldn't have been public.  That was a mistake on my part.
> > >
> > > On 7/7/06, Shawn Wildermuth <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Then why is the interface public?
> > > >
> > > >
> > > > Thanks,
> > > >
> > > > Shawn Wildermuth
> > > > Wildermuth Consulting Services, LLC http://adoguy.com C# MVP,
> > > > MCSD.NET, Author and Speaker
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Discussion of advanced .NET topics.
> > > > > [mailto:[EMAIL PROTECTED] On Behalf Of Mike
> > Andrews
> > > > > Sent: Friday, July 07, 2006 4:22 PM
> > > > > To: [email protected]
> > > > > Subject: Re: [ADVANCED-DOTNET] Implementing an Interface - C#
> > > > > vs. VB.NET
> > > > >
> > > > > The answer is that I want these methods to be utilized only
> > > > > within the context of the namespace they are in.  I
> don't want
> > > > > them accessible outside, but only used as internal
> features of
> > > > > the object.
> > > > >
> > > > > Thanks,
> > > > > Mike
> > > > >
> > > > > On 7/7/06, Shawn Wildermuth
> <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > Then I would:
> > > > > >
> > > > > > public abstract class T: IBusiness {
> > > > > >
> > > > > > public virtual void Remove() {
> > > > > >    throw new Exception("The method or operation is not
> > > > > implemented.");
> > > > > > }
> > > > > >
> > > > > > public virtual void Save() {
> > > > > >      throw new Exception("The method or operation is not
> > > > > > implemented."); }
> > > > > >
> > > > > > public virtual Guid ID {
> > > > > >    get {
> > > > > >      throw new Exception("The method or operation is not
> > > > > implemented.");
> > > > > >    }
> > > > > >    set {
> > > > > >      throw new Exception("The method or operation is not
> > > > > implemented.");
> > > > > >    }
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > I am not sure based on your explanation so far, why you
> > > > > need to hide
> > > > > > the methods/properties with protected/internal in the base
> > > > > class?  Its
> > > > > > abstract so you can't create an instance of it anyway.
> > > > > >
> > > > > > A derived class could:
> > > > > >
> > > > > > public class X : T
> > > > > > {
> > > > > > public override void Remove()
> > > > > > {
> > > > > >    // call base implemenation
> > > > > >    base:Remove();
> > > > > >
> > > > > >    // do more stuff
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > If you want to get fancy and unnecessary you could also:
> > > > > >
> > > > > > public abstract class T: IBusiness {
> > > > > >
> > > > > > public virtual void Remove() {
> > > > > >    innerRemove();
> > > > > > }
> > > > > >
> > > > > > // ... rest of interface
> > > > > >
> > > > > > protected internal void innerRemove() {
> > > > > >    // do remove work here
> > > > > > }
> > > > > >
> > > > > > // ... rest of interface
> > > > > > }
> > > > > >
> > > > > > But that seems silly to me...
> > > > > >
> > > > > > HTH
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Shawn Wildermuth
> > > > > > Wildermuth Consulting Services, LLC
> http://adoguy.com C# MVP,
> > > > > > MCSD.NET, Author and Speaker
> > > > > >
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Discussion of advanced .NET topics.
> > > > > > > [mailto:[EMAIL PROTECTED] On Behalf Of
> > > > > > > Mike Andrews
> > > > > > > Sent: Friday, July 07, 2006 4:06 PM
> > > > > > > To: [email protected]
> > > > > > > Subject: Re: [ADVANCED-DOTNET] Implementing an
> Interface -
> > > > > > > C#
> > vs.
> > > > > > > VB.NET
> > > > > > >
> > > > > > > Thank you.
> > > > > > >
> > > > > > > However, that does not help with the idea that a
> base class
> > > > > > > implements an interface and then I re-implement the
> > > > > > > interface on derived classes where needed.  This
> is so that
> > > > > > > ever class that inherits from the base class also
> implements
> > > > > > > the
> > > > > interface, even if
> > > > > > > I do not re-implement it for the derived class.  But some
> > derived
> > > > > > > classes will add their own functionality.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Mike
> > > > > > >
> > > > > > >
> > > > > > > On 7/7/06, gregory young <[EMAIL PROTECTED]> wrote:
> > > > > > > >
> > > > > > > > You have to do whats called "explicitly implementing" a
> > > > > > > interface. See
> > > > > > > > http://msdn2.microsoft.com/en-us/library/4taxa8t2.aspx
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Greg
> > > > > > > >
> > > > > > > >
> > > > > > > > On 7/7/06, Mike Andrews
> <[EMAIL PROTECTED]> wrote:
> > > > > > > > >
> > > > > > > > > Guys,
> > > > > > > > >
> > > > > > > > > I have a question that I need some help with
> in regards
> > > > > > > > > to implementing
> > > > > > > > an
> > > > > > > > > interface.
> > > > > > > > > I've been a VB programmer for most of my
> career and now
> > > > > > > > > I
> > > > > > > use C#.
> > > > > > > > > Some
> > > > > > > > of
> > > > > > > > > the functionality that I used in VB seems to
> be lacking
> > > > > > > > > in
> > C#.
> > > > > > > > > I wanted to know if it's my imagination or if
> there's a
> > > > > > > workaround.
> > > > > > > > >
> > > > > > > > > The base problem is that I want to change the access
> > > > > > > > > level
> > on
> > > > > > > > > interface methods once they are implemented
> in a class.
> > > > > > > However, C#
> > > > > > > > > seems to cry and such changes and VB seems to
> allow them.
> > > > > > > > > Here's the example:
> > > > > > > > >
> > > > > > > > > Here's the VB example:
> > > > > > > > >
> > > > > > > > > Public Interface IBusiness
> > > > > > > > >
> > > > > > > > >    Sub Remove()
> > > > > > > > >    Sub Save()
> > > > > > > > >    Property ID() As Guid
> > > > > > > > >
> > > > > > > > > End Interface
> > > > > > > > >
> > > > > > > > > Public MustInherit Class T
> > > > > > > > >    Implements IBusiness
> > > > > > > > >
> > > > > > > > >    Public MustOverride Sub DoStuff()
> > > > > > > > >
> > > > > > > > >    Protected Friend Overridable Property ID() As
> > > > > > > > > System.Guid Implements IBusiness.ID
> > > > > > > > >        Get
> > > > > > > > >
> > > > > > > > >        End Get
> > > > > > > > >        Set(ByVal value As System.Guid)
> > > > > > > > >
> > > > > > > > >        End Set
> > > > > > > > >    End Property
> > > > > > > > >
> > > > > > > > >    Protected Friend Overridable Sub Remove()
> Implements
> > > > > > > > > IBusiness.Remove
> > > > > > > > >
> > > > > > > > >    End Sub
> > > > > > > > >
> > > > > > > > >    Protected Friend Overridable Sub Save() Implements
> > > > > > > IBusiness.Save
> > > > > > > > >
> > > > > > > > >    End Sub
> > > > > > > > >
> > > > > > > > > End Class
> > > > > > > > >
> > > > > > > > > Notice in this example that these methods are the
> > > > > > > implementation for
> > > > > > > > > IBusiness, but I changed the access modifiers to
> > > > > > > > > Protected Friend
> > > > > > > > instead
> > > > > > > > > of
> > > > > > > > > public or something else.
> > > > > > > > >
> > > > > > > > > Now, in C#, if I try to do the same, I get a
> compiler error:
> > > > > > > > >
> > > > > > > > >    public interface IBusiness {
> > > > > > > > >
> > > > > > > > >        void Remove();
> > > > > > > > >        void Save();
> > > > > > > > >        Guid ID { get; set;}
> > > > > > > > >
> > > > > > > > >    }
> > > > > > > > >
> > > > > > > > >    public abstract class T: IBusiness {
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >        #region IBusiness Members
> > > > > > > > >
> > > > > > > > >        public void Remove() {
> > > > > > > > >            throw new Exception("The method or
> > > > > operation is not
> > > > > > > > > implemented.");
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > > >        public void Save() {
> > > > > > > > >            throw new Exception("The method or
> > > > > operation is not
> > > > > > > > > implemented.");
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > > >        public Guid ID {
> > > > > > > > >            get {
> > > > > > > > >                throw new Exception("The method or
> > > > > > > operation is not
> > > > > > > > > implemented.");
> > > > > > > > >            }
> > > > > > > > >            set {
> > > > > > > > >                throw new Exception("The method or
> > > > > > > operation is not
> > > > > > > > > implemented.");
> > > > > > > > >            }
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > > >        #endregion
> > > > > > > > >
> > > > > > > > >    }
> > > > > > > > >
> > > > > > > > > If I change the public members to protected or
> > > > > private I get an
> > > > > > > > error.  If
> > > > > > > > > I
> > > > > > > > > change them to explicit implementation, then I cannot
> > > > > > > > > access them regardless unless I cast to the interface.
> > > > > > > > >
> > > > > > > > > What I'm want to do is implement an interface
> in a base
> > class
> > > > > > > > > (so that I don't have to implement it in every derived
> > class)
> > > > > > > > > and then
> > > > > > > > "re-implement"
> > > > > > > > > for the derived class where necessary but have a
> > > > > > > protected internal
> > > > > > > > access
> > > > > > > > > modifier.
> > > > > > > > >
> > > > > > > > > Any suggestions or am I barking up the wrong
> tree here?
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > > Mike
> > > > > > > > >
> > > > > > > > > ===================================
> > > > > > > > > This list is hosted by DevelopMentor(r)
> > > > > http://www.develop.com
> > > > > > > > >
> > > > > > > > > View archives and manage your subscription(s) at
> > > > > > > > > http://discuss.develop.com
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > If knowledge can create problems, it is not through
> > > > > > > ignorance that we
> > > > > > > > can solve them.
> > > > > > > >
> > > > > > > > Isaac Asimov
> > > > > > > >
> > > > > > > > ===================================
> > > > > > > > This list is hosted by DevelopMentor(r)
> > http://www.develop.com
> > > > > > > >
> > > > > > > > View archives and manage your subscription(s) at
> > > > > > > > http://discuss.develop.com
> > > > > > > >
> > > > > > >
> > > > > > > ===================================
> > > > > > > This list is hosted by DevelopMentorR
> > > > > > > http://www.develop.com
> > > > > > >
> > > > > > > View archives and manage your subscription(s) at
> > > > > > > http://discuss.develop.com
> > > > > >
> > > > > > ===================================
> > > > > > This list is hosted by DevelopMentor(r)
> > > > > > http://www.develop.com
> > > > > >
> > > > > > View archives and manage your subscription(s) at
> > > > > > http://discuss.develop.com
> > > > > >
> > > > >
> > > > > ===================================
> > > > > This list is hosted by DevelopMentorR  http://www.develop.com
> > > > >
> > > > > View archives and manage your subscription(s) at
> > > > > http://discuss.develop.com
> > > >
> > > > ===================================
> > > > This list is hosted by DevelopMentor(r)  http://www.develop.com
> > > >
> > > > View archives and manage your subscription(s) at
> > > > http://discuss.develop.com
> > > >
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r)  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > > http://discuss.develop.com
> > >
> >
> >
> >
> > --
> > If knowledge can create problems, it is not through
> ignorance that we
> > can solve them.
> >
> > Isaac Asimov
> >
> > ===================================
> > This list is hosted by DevelopMentor(r)  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> >
>
> ===================================
> This list is hosted by DevelopMentorR  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to