title: Represent email, telephonenumber and id's as POJO's instead of Strings
body: <p>I have a typical business web application where the domain contains entities like accounts and users. My backend is Java, so they're represented by POJO's. During an early iteration, every attribute of those POJO's were just strings. This made sense because the html input was a string, and the way the data is persisted in the DB is also similar to a string.</p>
  
  <p>Recently, we've been working on validating this kind of input and I found it helps if I switch over to an object notation for this kind attributes. For example, a <code>TelephoneNumber</code> class consists of:</p>
  
  <ul>
  <li>(int) country calling code</li>
  <li>(string) rest of number</li>
  <li>(static char) the character to prefix the country calling code (in our case this is a +)</li>
  <li>(static pattern) regular expression to match if phonenumber is sensical</li>
  <li>methods to compare and validate telephone numbers.</li>
  </ul>
  
  <p>This class has advantages and disadvantages:</p>
  
  <ul>
  <li>not good: Additional object creation and conversion between string/object</li>
  <li>good: OOP and all logic regarding telephone numbers is bundled in one class (high cohesion),</li>
  <li>good: whenever a telephone number is needed as an argument for a method or constructor, java's strict typing makes it very clear we're not just dealing with a random string.</li>
  </ul>
  
  <p>Compare the possible confusing double strings:</p>
  
  <pre><code>public User(String name, String telephoneNumber)
  </code></pre>
  
  <p>vs the clean OOP way:</p>
  
  <pre><code>public User(String name, TelephoneNumber telephoneNumber)
  </code></pre>
  
  <p>I think in this case the advantages outweight the disadvantges. My concern is now for the following two attributes:</p>
  
  <p>-id's (like b3e99627-9754-4276-a527-0e9fb49d15bb)
  -e-mailadresses</p>
  
  <p>This "objects" are really just a single string. It seems overkill to turn them into objects. Especially the <code>user.getMail.getMailString()</code> kind of methods really bother me because I know the mailString is the only attribute of mail. However, if I don't turn them into an object, I lose some of the advantages.</p>
  
  <p>So <strong>my question</strong> is: How do you deal with this concepts in a web application? Are there best practices or other concerns to take into account?</p>