I am a Groovy-Newbie and this is a theoretical question
In a project I am working on, we have POJOs with setters of the following form:
// Java Code
public class Person {
private String name;
// Set the name value only if it changes, then mark the POJO dirty
public void setName(String name) {
if ((name == null) ? this.name != null : !name.equals(this.name)) {
this.name= name;
this.dirty = true;
}
}
}
Without arguing the philosophy of this approach, is it possible to use MOP in Groovy to automatically "inject" the equality checks and dirty flag setting (ala aspects)? As it stands, each of these setters needs unit testing because it contains "logic" code (as in Dierk König's interview on unit testing with Sven Haiges in the Grails podcast series). If the boilerplate setter code could be injected, these methods would not each need separate units tests.