Skip to content
Geoffrey Wiseman edited this page May 23, 2014 · 3 revisions

Access Modes allow you to control how properties are set, across an entire class, or for a particular property. There are two approaches: field access and method access. Field access attempts to write directly to the fields of the object, while method access uses setter methods.

In order to change the access mode for a class, annotate the class with @Access:

@Access(AccessMode.METHOD)
public class ClassWithSetters() {
}

On the other hand, if you simply want to tell moo to treat something as a property that doesn't match the access mode for the class, mark it with @Property:

public class FieldAccessible {
    private Name name;
    private String rank;
    private Integer serialNumber;

    @Property
    public setFirstName( String name ) {
        name.setFirstName( name );
    }

    @Property
    public setLastName( String name ) {
        name.setLastName( name );
    }
}

Access mode is not currently inherited. If you have a type hierarchy, you may need to apply the configuration to super and sub classes.

Access modes were added in Moo v1.1.