jeudi 28 mai 2015

How do I minimize object creation in this particular situation?

While implementing a database structure, my goal is to provide easy access to player data.

So, I have created the User class, which holds a Json instance and exposes the methods to take specific information from it.

public class User {
    private Json data;
    public User(UUID id) {
        data = new Json(id + ".json");
    }
    public boolean isPremium() {
        return data.getBoolean("premium");
    }
}

The problem is that I would have to create a new instance every time I needed to know something about the player. That's very expensive!

But since players stay online for a while, I will most likely need the same data at the same time. So, is there a design pattern for this particular situation?

Aucun commentaire:

Enregistrer un commentaire