lundi 5 mars 2018

What is super-lazy idiom? or super-lazy technique?

I've read this gists where James_D uses a "super-lazy" idiom for instantiating the properties, and implement Externalizable to work around the lack of Serialization support in the FX property classes.

private IntegerProperty id ;
private int _id ;
@Id
@Column(name="inv_id")
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
    if (id==null) {
        return _id ;
    } else {
        return id.get();
    }
}

public void setId(int id) {
    if (this.id==null) {
        _id=id ;
    } else {
        this.id.set(id);
    }
}

public IntegerProperty idProperty() {
    if (id==null) {
        id = new SimpleIntegerProperty(this, "id", _id);
    }
    return id ;

}

So what is this? is a pattern, technique, methodology.

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire