|
-
Apr 28th, 2004, 08:30 PM
#1
Thread Starter
Frenzied Member
A class, it's method and self-referencing
I created this class and a method. the method is used to submit data to a DB. that data is actually an object created from the same class. W
What I'd like to know is, is it considered good practice to use the Private variables(fields) or should you still use the object.properties? ex:
VB Code:
public class Loan
private strName as string 'the field
public property Name() as string
get
return strName
end get
set
..
..
end set
public function SubmitData() as something
send strName to DB 'OR
send LoanObject.Name to DB
end function
That's pretty close anyway. I am currently sending the variables' data and NOT sending the data as properties. Which is more efficient? Which is better?
-
Apr 28th, 2004, 09:38 PM
#2
PowerPoster
The answer is.... it depends.
If you are just returning the variable, what would it matter? It is probably more efficient to just use the variable, but that efficiency isn't going to be noticed at all I would think.
I tend to use the properties though for readability in my code. The other reasons would be if you are doing something dynamic in the property to return a modified value. You may want that instead of what is in the property itself.
-
Apr 28th, 2004, 09:42 PM
#3
PowerPoster
To help visualize what I mean more:
VB Code:
public class Loan
private objLoanParent as LoanParentObject
public property ParentID() as integer
get
return objLoanParent.ID
end get
End Property
public function SubmitData() as something
send objLoanParent.ID to DB
'OR
send Me.ParentID to DB
end function
End Class
Or better yet:
VB Code:
public class Loan
private objLoanParent as LoanParentObject
public property NextParentID() as integer
get
return objLoanParent.ID + 1
end get
End Property
public function SubmitData() as something
send objLoanParent.ID + 1 to DB
'OR
send Me.NextParentID to DB
end function
End Class
-
Apr 29th, 2004, 06:38 AM
#4
Fanatic Member
Like hellswraith, I also tend to use properties. IMHO it makes the code more extensible (for cases where you need to do something to the data before you return it, etc.).
-
Apr 29th, 2004, 07:30 AM
#5
Thread Starter
Frenzied Member
cool. thanks for the suggestions guys! I tried a little bit of both and like the readability of using the properties too. PLUS, I found out that if you're inheriting from another class, you kinda HAVE to use properties 
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|