lundi 4 septembre 2017

Best design pattern this?

i have problem how to represent my structure in memory in Java. I need save something like this:

class Column {

    private MapItem item;

    public Column(MapItem item) {
        this.item = item;
    }

    private String cssClass;
    private String name;
    private String message;
    private boolean visible;

    public String getCssClass() {
        //for every Column return different data from same item obj.
    }

    public String getName() {
        //for every Column return different data from same item obj.
    }

    public String getMessage() {
        //for every Column return different data from same item obj.
    }

    public boolean isVisible() {
        return visible;
    }
}

Next I need create instace Column for 14times.

class Table {

    public Table(MapItem item) {
        this.name = new Column(item);
        this.type = new Column(item);
        this.city = new Column(item);
        this.street = new Column(item);
        ...
    }

    private Column name;
    private Column type;
    private Column city;
    private Column street;
    ...
}

I cannot use Enum cause i need this serialize to database. Know someone elegant solution? Polymorfism seems to be best solution for me, but create 14 files for every Column + one abstract is little bit overkill, isn't it?

Aucun commentaire:

Enregistrer un commentaire