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: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> 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Ā®  http://www.develop.com

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

Reply via email to