jeudi 28 janvier 2016

Search for pattern - filling model

im writing a java application where i have to fill plain objects with values.

example object

public class A {
    private String a;

    private String b;

    // ...

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    // ...
}

i fill it like this

public class Initalizer {
    public A init()  {
        A a = new A();

        a.setA(// get it from somewhere
        );
        a.setB(// get it from somewhere
        );
        // ...

        return a;
    }
}

in this case, i get the values from jsoup, a html-parser

my question is: is there a more elegant way? like defining one method for filling one property. like in lego where one stone fits the other.

is there a design-pattern i don't know?

thanks for help

Aucun commentaire:

Enregistrer un commentaire