title: Java Encapsulation & OOP Best Practice
body: <p>I implemented a class called mobileCall. I create several objects from this class and populate the String variables of this object with values coming from an XML having several mobileCalls for specific person. I need to group and count all calls made by this person (i.e. national calls: 11 mins; international calls: 15 mins; data: 20 MB)</p>
  
  <p>So, I implemented several public methods inside the class to check the type of the call to return true or false. And in the main class I called these methods to check if they satisfy the criteria I count up the specific counter.</p>
  
  <p>Someone professional saw my code and said that this is not a good practice and OOP was designed to eliminate such 'what are you' methods. And that there are better ways to implement this behavior. I tried to read through OOP and Encapsulation but could not figure out a better way to do it. I feel he has a point, tho.</p>
  
  <p>Code Example</p>
  
  <pre><code>public class MobileCall {
  
      String callType;
      String callDuration;
      String callAmount;
      String callerID;
      String calleID;
      ....
      public boolean isNational(){
  
          if (callType.compareTo("National")==0)
              return true;
          else
              return false;
      }
  
      public boolean isInternational(){
  
          if (callType.compareTo("international")==0)
              return true;
          else
              return false;
      }
      ...
  }
  
  In Main Method
  
  int nationalCounter;
  int internationalCounter;
  MobileCall mobileCall = new MobileCall();
  
  if(mobileCall.isNational())
      nationalCounter = nationalCounter + mobileCall.getCallDuration();
  else if (mobileCall.isInternational())
      internationalCounter = internationalCounter + mobileCall.getDuration();
  ....
  </code></pre>