title: Nested Objects Best Practice
body: <p>What is the best practice for referencing nested objects?</p>
  
  <p>Say I have the following:</p>
  
  <pre><code>class Outer {
   private InnerA innerA;
   //getters and setters
  }
  
  class InnerA {
    private InnerB innerB;
    //getters and setters
  }
  
  class InnerB {
    private String someString;
    //getters and setters
  }
  </code></pre>
  
  <p>and in my controller or service class I need to check the someString String variable of the InnerB class to make sure it is not null or not empty so I do this:</p>
  
  <pre><code>if (getOuter().getInnerA().getInnerB().getSomeString() != null &amp;&amp; !getOuter().getInnerA().getInnerB().getSomeString().equalsIgnoreCase("") {
    //do something
  }
  </code></pre>
  
  <p>To me this looks messy and could have issues if the nested objects themselves are null.</p>
  
  <p>Do I create getters ans setters in the parent objects for the child objects checking for null?  Just wondering what the best practice was if any and/or what some of you do in your code?</p>