I'm working on a class and I'm curious about setting properties values.
I'm just getting started in OOP and I'm using some online examples. I've been able to successfully incorporate 2 main classes into my application.
I'm curious about how to make this work or possibly a different method:
Code:
Public Class Foo
Private privID
Private privName
Private Sub Class_Initialize()
' granted the pID isn't set yet, but maybe define another method to get it
' this was all just flying by the seat of my pants
Call mGetName
End Sub
Public Property Get pID
pID = privID
End Property
Public Property Let pID(value)
privID = value
End Property
Public Property pName
pName = privName
End Property
Private Sub mGetName
' some query here WHERE ID = pID
privName = [query results]
End Sub
End Class
Dim cFoo, Name
Set cFoo = New Foo
cFoo.pID = (Form/QueryString/Session)
Name = cFoo.pName
<%= cFoo.pName %>
Versus this idea:
Code:
Public Class Foo
Private privName
Public Property Get pName
pName = privName
End Property
Public Property Let pName(value)
privName = value
End Property
Private Function mGetName(value)
' some query here WHERE ID = value
mGetName = [query results]
End Function
End Class
Dim cFoo, Name
Set cFoo = New Foo
cFoo.pName = cFoo.mGetName(Form/QueryString/Session)
<%= cFoo.pName %>
Any advantage of one technique over the other? I'd imagine there are even other techniques.
Any insight is appreciated.