title: How to restrict access to object for one specific class in Java? If possible, by implementing a design pattern
body: <p>I am writing a code where I have some SharedData object(single object) between Admin object(single object) and User objects. Only one person(Admin or User) should be able to access SharedData at a time, I am using synchronised locks currently. For accessing SharedData, currently I am keeping the SharedData object in the Admin and User class.
  The problem is I want to restrict Users from changing some members of SharedData. But, the Admin object should still be able to change SharedData.</p>
  <p><strong>Note: The admin and user classes are very different, I can't extend user to create Admin. Admin is not just like user here.</strong>
  Some code for better understanding
  SharedData</p>
  <pre><code>public class SharedData {
      public ArrayList&lt;Integer&gt; numbersShown = new ArrayList&lt;Integer&gt;();
      public boolean completeFlag = false;    
  }
  </code></pre>
  <pre><code>public class Admin implements Runnable {
      
      private SharedData SharedData;
      //OTHER MEMBERS
      run()
      {
      //Change numberShown
      }
  
  }
  public class User implements Runnable {
      
      private SharedData SharedData;
      //OTHER MEMBERS
      run()
      {
      //not able to change numberShown
      }
  }
  </code></pre>