Hello
I have a general best practices type question.
I am wondering if its ok to assign values to a private pVariable directly, when I have public and private functions that will edit these values and pVariable is not supplied as an argument to these functions.
For instance, I am creating a FileSearch Class that holds a private variable pCurrentSearchHit
This property is meant to be read only in its public interface, and so it seems I have two options.
I realize that filtering through a Private Property Let procedure provides more quality checks, but may not be necessary as the public properties which ultimately define this variable have several checks in place.
Also, when a Private Let procedure is in place the client code does not recognize the property as read only, and instead throws a data member not found error when the client tries to directly assign .CurrentSearchHit a value.
Is there a right/wrong way to do this, and do I gain anything significant by accessing the Private pCurrentSearchHit directly?
I have a general best practices type question.
I am wondering if its ok to assign values to a private pVariable directly, when I have public and private functions that will edit these values and pVariable is not supplied as an argument to these functions.
For instance, I am creating a FileSearch Class that holds a private variable pCurrentSearchHit
This property is meant to be read only in its public interface, and so it seems I have two options.
1. Have the methods that write to this variable access the pCurrentSearchHit directly.
2. Create a Private Property Let procedure to assign the variable.
It seems that writing to the private variable is more efficient, although I am really not sure how much of a performance hit filtering the property through a let or get procedure incurs. For instance, what if a function needs to reference that variable several times? Code:
Private Function fReassignCurrentHit() As String
pCurrentSearchHit = pFilePath & pFileName & pFileExtension
End Function
Code:
Private Function fReassignCurrentHit() As String
Me.CurrentSearchHit = Me.FilePath & Me.FileName & Me.FileExtension
End Function
I realize that filtering through a Private Property Let procedure provides more quality checks, but may not be necessary as the public properties which ultimately define this variable have several checks in place.
Also, when a Private Let procedure is in place the client code does not recognize the property as read only, and instead throws a data member not found error when the client tries to directly assign .CurrentSearchHit a value.
Is there a right/wrong way to do this, and do I gain anything significant by accessing the Private pCurrentSearchHit directly?