Click to See Complete Forum and Search --> : Need opinion on class design


Aleksey
09-15-2002, 08:03 PM
Hi, I need opinion on the class design. Let me give you an example. Lets say
I have special class (CApp) which have property CDb. By default CApp doesn't
do anything on initialize, but as soon as CDb propery called class checks
if database connection has been initialized before. If yes it passes Connection
object to that property, if no it initializes and opens connection and passes
newly initialized connection object to that property. Here is an example.


Dim oConnection
Class CApp
Public Sub Class_Terminate
oConnection.Close
oConnection = Nothing
End Sub
Public Property Get CDb()
If oConnection Is Nothing Then
'open connection
End If
Set CDb = oConnection
End Property
End Class

Here is example of usage...
....
oCApp.CDb.Execute(sSQL)
....
or if I need to use it more than once
....
With oCApp.CDb
.Execute(~select statement~)
.Execute(~select statement~)
.Execute(~select statement~)
End With
....

Do you think that would be a good idea to do the same thing with custom made
objects/classes?

Thanks for any help!!