Is it a bad practice to access a data item directly?

I remember how the professor said it was bad practice. But it makes going through code a lot less tedious. I just make out the comments about the pros and cons:

Friend Class MyClass
 Private isEmpty As Boolean
 Public Property IsEmpty() As Boolean
  Get
   Return isEmpty
  End Get
  Set(ByVal Value As Integer)
   isEmpty = value
  End Set
 End Property
 Public Sub MyMethod()
  ''//Is this more correct:
  If Me.IsEmpty() Then
   ''//Do something.
  End If
  ''//Is this bad practice?:
  If isEmpty Then 
   ''//Do something.
  End If
 End Sub
End Class 
+3
source share
3 answers

If you created a property to access the private member variable "isEmpty" than "yes", I would use the property inside the class itself if you have no reason to.

, , (, , ), , , .

+4

Ed, IDE , , getter/seters, . VB, #/VS2008 . , , , , " " .

+3

. , - , . , .

, , . .

0
source

Source: https://habr.com/ru/post/1756633/


All Articles