Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] Q: MOP, aspects, setter methods

grkuntzmd

2008-08-21

Replies: Find Java Web Hosting

Author LoginPost Reply

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.

G. Ralph Kuntz, MD
Chief Software Architect
meridianEMR, Inc.


View this message in context: Q: MOP, aspects, setter methods
Sent from the groovy - user mailing list archive at Nabble.com.
©2008 gg3721.com - Jax Systems, LLC, U.S.A.