title: Why protected member variables are considered an anti-pattern and should be replaced with private access fields?
body: <p>I was recently given advice to change all my protected member variables in the base class to private access. </p>
  
  <p>But the only advantage that comes to mind in terms of real usage is to just be able to give separate Read, Write and Read/Write access to them to protect against misuse. The following Java code details this use.</p>
  
  <pre><code>public class BaseClass {
      protected Object protectedMember;
  
      private Object privateMemberR;
      private Object privateMemberW;
      private Object privateMemberRW;
  
      public BaseClass() {
  
      } 
  
      protected final Object getPrivateMemberR(Object obj){
          return privateMemberR;
      }
  
      protected final void setPrivateMemberW(Object obj){
          privateMemberW = obj;
      }
  
      protected final Object getPrivateMemberRW(Object obj){
          return privateMemberRW;
      }
  
      protected final void setPrivateMemberRW(Object obj){
           privateMemberRW = obj;
      }
  }
  </code></pre>
  
  <p>Maybe declaring them final is not always needed, only to be sure that they are not overwritten and misused.</p>
  
  <p>I read similar arguments like this <a href="https://softwareengineering.stackexchange.com/questions/162643/why-is-clean-code-suggesting-avoiding-protected-variables">Clean code questions</a>, but if I could have gotten away with private member variables, I would have made them private in the first place. </p>
  
  <p>Furthermore, since at least in Java you can only have the access modifier for an overwritten method to allow more, but not less, access than the superclass method, you are still gonna drag either protected member variables or protected getters and setters all the way up in your subclasses.</p>
  
  <p>I have not considered multiple inheritance since Java does not allow it, but still I do not see how using standard notation for getters and setters you could avoid running into problems.</p>
  
  <p>Is there any other actual benefit in terms of real usage (other than it looks more pretty and easier to read, magically hope you protec against improper use by replacing direct reference with getters and setters)</p>