A
AllenL
Ever since I've been using objects with VB I've instantiated the
business object from the form; the business object then
creates/destroys data access layer objects as needed. The business
object also maintains state for the form variables. The form unload /
closing event destroys the business object.
For a small set of specialized forms in .NET, I want to try switching
the usual order of things. The business class will optionally
instantiate the form (modal), passing a reference of itself in the
form constructor as in:
from any code in the application...
Private cMy As MyClass
cMy = New MyClass(True)
or
Private cMy As MyClass = New MyClass(True)
If IsNothing(cMy) = False Then cMy = Nothing
------------------------------------------
If the parameter in the class constructor is True, the form will show
as in:
MyClass
Private cF As MyForm
Friend Sub New(ByVal bDisplayForm as Boolean)
If bDisplayForm Then DisplayForm
End Sub
Private Sub DisplayForm
cF = New MyForm(Me) ' pass reference to class
cF.ShowDialog()
End Sub
...various properties that tie to variables on the form
------------------------------------------
MyForm
Private cMy2 As MyClass
Friend Sub New(By Ref c As MyClass)
cMy2 = c
End Sub
' cMy2 and cMy should now point to the same object
' business class properties/methods are now visible at form
' level
QUESTION:
Both business and form objects will be in the same runtime location.
The class will destroy the form. Does anyone see any potential
problems with this methodology?
Thanks.
****** AllenL ********************************************************
In a nation ruled by swine, all pigs are upward-mobile...
Hunter S. Thompson (b. 1939), U.S. journalist.
business object from the form; the business object then
creates/destroys data access layer objects as needed. The business
object also maintains state for the form variables. The form unload /
closing event destroys the business object.
For a small set of specialized forms in .NET, I want to try switching
the usual order of things. The business class will optionally
instantiate the form (modal), passing a reference of itself in the
form constructor as in:
from any code in the application...
Private cMy As MyClass
cMy = New MyClass(True)
or
Private cMy As MyClass = New MyClass(True)
If IsNothing(cMy) = False Then cMy = Nothing
------------------------------------------
If the parameter in the class constructor is True, the form will show
as in:
MyClass
Private cF As MyForm
Friend Sub New(ByVal bDisplayForm as Boolean)
If bDisplayForm Then DisplayForm
End Sub
Private Sub DisplayForm
cF = New MyForm(Me) ' pass reference to class
cF.ShowDialog()
End Sub
...various properties that tie to variables on the form
------------------------------------------
MyForm
Private cMy2 As MyClass
Friend Sub New(By Ref c As MyClass)
cMy2 = c
End Sub
' cMy2 and cMy should now point to the same object
' business class properties/methods are now visible at form
' level
QUESTION:
Both business and form objects will be in the same runtime location.
The class will destroy the form. Does anyone see any potential
problems with this methodology?
Thanks.
****** AllenL ********************************************************
In a nation ruled by swine, all pigs are upward-mobile...
Hunter S. Thompson (b. 1939), U.S. journalist.