jeudi 14 octobre 2021

Is there a problem in constantly been updating properties of an object created with singleton?

I´m using a Response object in order to create http responses. My responses are objects created with a function and using several parameters, one of these parameters is a string getted from a method of an object that makes a quick query of some data inside the code itself. The problem is that to every new Response represents a new Response object, and I´m trying to get a better performance creating the Response object with a singleton design pattern, but I don´t know if there are some consequenses because of being constantly updating the server´s running object´s properties to change the especifict data I´m quering at every response time or even if there is a better way of getting a better performance without using a singleton design pattern.

In this example I18n.getString() is the method I would be constantly changing the parameters in order to get new data

const okResponse = function (data, locale) {
return (new Response(200, "SUCCESS", true, I18n.getString(locale, 'ok-title'), I18n.getString(locale, 'ok-message'), data, {}, new Date())).toJSON()

}

Aucun commentaire:

Enregistrer un commentaire