Skip to content
Jan Krüger edited this page Oct 31, 2015 · 3 revisions

Welcome to the DataHolder wiki!

Why should you use DataHolder and why is it so useful?

The main idea is to provide a lib that allows you to design better data APIs. The most APIs have a lot of methods to retrieve or set data or better known as "get/set"-methods, but what could you do when you would have only one method to get and to store data? This improves the complete work and data flow of your project because everybody who is using your project just knows that he gets all data through the DataCarrier#getProperty method.

Example without DataHolder

public class Player {

    private String name;
    private double health;
    private List<Player> friends = new ArrayList<Player>();

    public Player(String name, double health) {
        this.name = name;
        this.health = health;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHealth() {
        return this.health;
    }

    public void setHealth(double health) {
        this.health = health;
    }


    public List<Player> getFriends() {
        return this.friends;
    }

}

Example with DataHolder

public class Player extends DataHolder {


    public Player(String name, double health) {

        this.store(new StringProperty<>("name", name));
        this.store(new DoubleProperty<>("health", health));
        this.store(new ListProperty<>("friends", new ArrayList<Player>()));

    }


}

The main advantage is that developers don't have to worry about deprecated methods.

Clone this wiki locally