Overloads/Shadows question

  • Thread starter Thread starter Jeff Johnson [MVP: VB]
  • Start date Start date
J

Jeff Johnson [MVP: VB]

I'm developing a form which is to be used as an enhanced MessageBox(). I
don't want it to be shown with the default Show() method, so as I provided
overloaded versions of Show() I marked them as Shadows and I didn't provide
a parameterless version of Show(). Would it have been better (or would this
have even worked) to simply make a Private version of Show() and only
exposed (i.e., made Public) the other overloads?
 
If you dont want the default contructor.

Class MyMessageBox
Inherits MessageBox
Public Sub New( your ParameterList )
MyBase.Show( yourParameterList )
End Sub

Or

Class MyMessageBox
Inherits MessageBox
Public Sub New( )
MyBase.Show( yourDefaultParameterList )
End Sub






--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
If you dont want the default contructor.

Class MyMessageBox
Inherits MessageBox
Public Sub New( your ParameterList )
MyBase.Show( yourParameterList )
End Sub

Or

Class MyMessageBox
Inherits MessageBox
Public Sub New( )
MyBase.Show( yourDefaultParameterList )
End Sub

This isn't a question about constructors but rather about hiding the Show()
method that is inherited from the Form class. I'm not wrappering
MessageBox(). This is a complete replacement based on Form. I should have
mentioned that.
 
Why do you not use the form.showdialog method which is made for this?

Because I want this form to be used exactly the way people are used to using
MessageBox(), and that's MessageBox.Show(...). It calls ShowDialog()
internally.
 
Jeff,
In addition to the other comments.

The "problem" with shadowing the Show method in your derived form is that I
can put an instance of your form in a Form variable and call the Show
method!

Public Class JeffsMessageBoxForm
Inherits Form

...

Public Shadows Sub Show(ByVal requiredParm As String)
End Sub
End Class

Dim frm As Form = New JeffsMessageBoxForm
frm.Show()

I find Shadows to be best used for versioning control. Only.

In the few places where I wanted to do this, I have:
1. Created a normal class that has the Shared Show methods on it (similar to
MessageBox), and the form itself is Private (friend) to the assembly.

Friend Class JeffsMessageBoxForm
Inherits Form

End Class

Public NotInheritable Class JeffsMessageBox

Private Sub New
End Sub

Public Shared Sub Show(ByVal requiredParm As String)
Dim frm As New JeffsMessageBoxForm
frm.Show()
End Sub

End Class

2. Allow the Show to be called, and just make a point not to call it.



If I did decide to use Shadows, I would Shadow both, marking the existing
one Obsolete:

<Obsolete("Use Show(requiredParm)", True)> _
Public Shadows Sub Show()
MyBase.Show()
End Sub

Public Shadows Sub Show(ByVal requiredParm As String)
...
MyBase.Show()
End Sub

Hope this helps
Jay
 
In the few places where I wanted to do this, I have:
1. Created a normal class that has the Shared Show methods on it (similar to
MessageBox), and the form itself is Private (friend) to the assembly.

I like this. I was thinking of going the
all-shared-method-don't-allow-instantiation route anyway. This has convinced
me.

So much to learn....
 
Back
Top