What do you suggest in it's place? I'm looking for something similar, but I'm uncertain as to how to do it.
Thanks, Mike On 7/7/06, Shawn Wildermuth <[EMAIL PROTECTED]> wrote:
I would probably *not* have the abstract class implement the interface, since you'll need to have your derived classes expose the interface as public members. Then your derived classes could just call the protected/internal methods to do the work of the interface. I am not sure why VB.NET allows this but it makes no sense to me (unless of course a public/internal implmentation in VB.NET is just like a explicit interface implementation). 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 3:51 PM > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: [ADVANCED-DOTNET] Implementing an Interface - C# vs. VB.NET > > 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 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Ā® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com