Base Class Events

Is there going to be support in 2005 for a MustOverride Event in VB.NET or maybe RaiseEvent MyBase.EventName As it is now, you cannot raise a base class event in the form of MyBase.EventName. I know the workaround is maybe to add a method in the base class that raises the event but that doesnt make too much sense to me. Especially when you have an abstract base class but you also have these non virtual/virtual methods thrown in there to raise events in the base class. Maybe I am being picky but I like to keep my abstract base classes abstract and not have these workarounds thrown in to the mix.


Answer this question

Base Class Events

  • Juan Camilo

    This is what I was referring to. I don't like that design choice. Throwing extra methods in an abstract class in order to raise events. It doesnt make sense in an abstract base class. That was the point of the original post, sorry if you misunderstood some guy.

  • SHANOND

    From the Design Guidelines for Class Library Developers:

     Design Guidelines for Class Library Developers wrote:

    Use a protected (Protected in Visual Basic) virtual method to raise each event. This technique is not appropriate for sealed classes, because classes cannot be derived from them. The purpose of the method is to provide a way for a derived class to handle the event using an override. This is more natural than using delegates in situations where the developer is creating a derived class. The name of the method takes the form OnEventName, where EventName is the name of the event being raised.


    Example:


            Public Event Click(ByVal sender As Object, ByVal e As EventArgs)

            Public Overridable Sub OnClick(ByVal e As EventArgs)
                RaiseEvent Click(Me, e)
            End Sub

     


  • WIPIT

    What is the workaround if we are deriving from .net FCL
  • Gabest

     Joe Smugeresky wrote:
    This is what I was referring to. I don't like that design choice. Throwing extra methods in an abstract class in order to raise events. It doesnt make sense in an abstract base class. That was the point of the original post, sorry if you misunderstood some guy.

    Joe,

       The reason you have to do this is that it is a security issue in .NET for code outside of the declaring type to fire events on that type.  Because of this, the option you outlined is the only one available.  All things considered, I'd rather be secure knowing that the events on a component are not being manipulated outside of that component.

       Hope this helps.

          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard.caspershouse.com

  • Base Class Events