Public Class frmMain
Private p_dlgAdd As frmAdd = Nothing
Public ReadOnly Property _dlgAdd As frmAdd
Get
If p_dlgAdd Is Nothing Then
p_dlgAdd = New frmAdd()
End If
Return p_dlgAdd
End Get
End Property
Public Sub DoStuff()
''// Should not touch p_dlgAdd
End Sub
End Class
For a few types of objects I would prefer to initialize them only when needed (sql connection, mainframe connections, large forms), because some users only use very specific parts of the program (managers may use one mainframe to do what they want, regular users use another resource primarily).
Why the p_? I am thinking using p_ would help me not use or easily find in intellisense the variable instead of the property locally in that class. Then using _ alone in front of private properties or private variables that don't need to locally be accessed by a property.
What would be a good way to help prevent me from accidently accessing p_dlgAdd directly? Is this a good use for anonymous variables in 2008? (I don't have 2008 available at work yet, but they think we will have it soon)