title: VB.NET - Misusing instance variables?
body: <p>Please take a look at the code below:</p>
  
  <pre><code>    Public Class A
      Public person1 As Person
  End Class
  
  Public Class B
      Inherits A
  
      Public Function CheckGender() As Boolean
          If person1._Gender = "M" Then
              CheckGender = True
          End If
      End Function
  
  End Class
  
  Public Class C
      Inherits B
      Public Function CheckAge() As Boolean
          If person1._Age &gt; 30 Then
              CheckAge = True
          End If
      End Function
  
  End Class
  
  Public Class D
      Inherits C
  
      Public Sub SomeMethod()
          Dim list As List(Of Person) = New List(Of Person)
          Dim p1 As New Person("Ian", "M", 31)
          Dim p2 As New Person("Susan", "F", 20)
          Dim p3 As New Person("Mark", "M", 22)
          list.Add(p1)
          list.Add(p2)
          list.Add(p3)
  
          For Each Person As Person In list
              person1 = Person
              If CheckAge() And CheckGender() Then
                  'Do something
              End If
          Next
      End Sub
  
      Public Shared Sub Main()
          Dim d As New D
          d.SomeMethod()
      End Sub
  
  End Class
  
  Public Class Person
      Public _Name As String
      Public _Gender As String
      Public _Age As String
      Public Sub New(ByVal Name As String, ByVal Gender As String, ByVal Age As Integer)
          _Name = Name
          _Gender = Gender
          _Age = Age
      End Sub
  End Class
  </code></pre>
  
  <p><code>c.SomeMethod</code> loops through three persons and does two checks: <code>b.CheckGender</code> and <code>c.CheckAge</code>.  <code>CheckGender</code> and <code>CheckAge</code> use an instance variable from the superclass <code>A</code>.  </p>
  
  <p>The code in the live environment loops through 100,000 records daily in a database and deletes those where <code>CheckGender</code> and <code>CheckAge</code> are both true.  <strong>Is it a bad design choice to use instance variables in this scenario?</strong>  I was always taught to use local variables.  I would expect the <code>Person</code> object to be passed to <code>CheckGender</code> and <code>CheckAge</code> on each loop. Or does it really not matter?</p>
  
  <p>Please note that the above code is a hypothetical example.  <code>CheckGender</code> and <code>CheckAge</code> are complex functions in the actual application. </p>