title: Accessing methods and variables in java
body: <p>Basically, in my app, I have a class called <strong>Resources</strong> which is where I create and hold all of my objects.</p>
  
  <p>When I create an object, let's call it myObject, I need to be able to access various methods and /or variables from the resource class, so at the moment, I am doing something like this:</p>
  
  <pre><code>public class Resources {
  
      int height;  //This will hold the height of the current device's screen (in pixels).  For the purpose of this question, please assume this has been intialised at some point.
  
      public void createObjects(){
  
          MyObject myObject = new MyObject(this); //Pass reference to this (Resources) class into constructor
  
      }
  
      public void method1(){
  
         //Do something here, this method could do some work or could be a proxy method to another class
  
      }
  
  }
  </code></pre>
  
  <p>So my 'MyObject' class would look something like so:</p>
  
  <pre><code>public class MyObject{
  
      Resources resources;    
      int yPosition;
  
      public MyObject(Resources resources){
  
          this.resources  = resources;
  
      }
  
      public intialise(){
  
          //Some examples
          resources.method1();
          yPosition = (resources.height)/2;
  
      }
  
  }
  </code></pre>
  
  <p>As I said, my Resources class is just that - it holds all of my objects and other important information (such as screen size etc.) so I need to access this class from within the objects that I create (so I can keep all code relating to that object within the object itself rather than externally (directly in the Resources class for example which would be really messy).</p>
  
  <p>I've been doing this and it hasn't caused any issues, and I realise that I'm simply passing a reference to my 'resources' object, what I would like to know is, is this an 'acceptable' way to access that which I need to?</p>