title: Null Object Pattern to avoid Null checks?
body: <p>Lately I have come across Null Object design pattern and my colleagues say it can be used to do away with the null pointer checks that are encountered throughout the code. </p>
  
  <p>for e.g suppose a DAO class returns information on Customer (in a value object called CustomerVO). My main class is supposed to extract the firstName and emailId and send email to customer. </p>
  
  <pre><code>...
  CustomerVO custVO = CustomerDAO.getCustomer(customerID);
  if(custVO != null) { // imp, otherwise we may get null ptr exception in next line
       sendEmail(custVO.getFirstName(), custVO.getEmailID());
  }
  ...
  </code></pre>
  
  <p>This is very simple example, but such null checks can quickly spread throughout your code based on the complexity of the value objects. </p>
  
  <p>I have two issues with null check, 
   - they tend tmake the code ugly and hard to read
     - lesser experienced developers put unnecessary null checks when in fact they are supposed to throw exceptions. for e.g. in above code, it would be better to throw exception from getCustomer() itself because if its not able to find customer info for given CustID, it indicates the CustID was invalid. </p>
  
  <p>okay, coming back to null object pattern, can we use a 'null' CustomerVO object to hide the null check?</p>
  
  <pre><code>CustomerVO {
     String firstName = "";
     String emailID = ""; 
  }
  </code></pre>
  
  <p>Don't it would make sense. what do you think?</p>
  
  <p>And what are the things you follow to minimize null checks in your app. </p>