I want to start incorporating the practice of writing invariants for my classes. For my POJOs, is it a good practice to validate its state by validating it against business rules. Say I have this class for instance:
@Data
public class Pick {
List<Substitution> substitutions = new ArrayList<>();
}
Now, my invariant says that every substitution object in the list needs to have a substitution reason. Is it a good practice to do such business checks inside POJOs that are meant to be simple data carriers?
Note that I already use @NonNull which is also an invariant, although a very basic one. Is it a good practice to write invariants that test for complex business relationships b/w your fields?