jeudi 14 mai 2020

Design Pattern to load data from database faster

I have a class of a Student. When I call a method that gets a client, it returns a newly created Student object. The constructor of Student gets the required data from the database by calling the method getStudentData. However, getStudentData takes an incredibly long time due to the nature of the database.

I initially implemented a factory design pattern, but it did not work as I had hoped. Note that I have to use getStudentData, and I am unable to change the database.

The Student class is as below:

public class StudentImplementation implements Student {

private final int key;
private String givenName;
private String surname;
private String contactNumber;
private String email;
private String address;

    public StudentImplementation(Login account_tokenizer, int key) {

        this.key = key;
        this.givenName = Table.getInstance().getStudentData(account_tokenizer, key, "givenName");
        this.surname = Table.getInstance().getStudentData(account_tokenizer, key, "surname");
        this.contactNumber = Table.getInstance().getStudentData(account_tokenizer, key, "contactNumber");
        this.email = Table.getInstance().getStudentData(account_tokenizer, key, "email");
        this.address = Table.getInstance().getStudentData(account_tokenizer, key, "address");

    }

// The rest of the class is full of getters
}

Aucun commentaire:

Enregistrer un commentaire