Validation inside Pojo
<p>This is more of a design question. </p>

<p>I have a POJO class defined like,  </p>

<pre><code>class MyPOJO {  
    private String memberVariable;  
    MyPOJO(String memberVariable) {  
      validate(memberVariable);
      this.memberVariable = memberVariable;
    }  
}
</code></pre>

<p>My question is how far can we go while validating the memberVariable constructor parameter. Is the following validate method impl acceptable,</p>

<pre><code>private validate(final String memberVariable) {
    Validate.isNotNull(memberVariable); // this is basic check.
    Validate.isTrue(memberVariable.indexOf(" ") == -1); //again a basic check.
    List&lt;String&gt; validValues = DBFactory.getDB().getValidValues();
    Validate.isTrue(validValues.contains(memberVariable)); // checks if the memberVariable value is present in db.
}
</code></pre>

<p>The argument behind doing strict checks in the constructor of the POJO is that we can be sure that a MyPOJO instance will never be created with any random memberVariable.
My question is whether this is a good design scheme? or should the validation logic be pulled out of POJO all together?         </p>
