lundi 5 octobre 2020

Can I have data validation inside of a factory?

I'm writing a mobile application (but I think it is not important in this case). I have factory that creates objects and fills them with data based on code passed to creation method. Some codes have well known structure and for those codes I can easily create appropriate object. However there are also codes that I can not resolve on a device. I have to send them to server and download their data.

In other words:

I have a factory that creates objects based on passed code. First I want to check if application can recognize this code. If it is ok I want to create object and return it. If not then I want to send it to server. As a response I will receive all data necessary to create object or information that this code is incorrect (or not found).

My problem is where to put this validation logic? Can I have it inside of a factory?

Aucun commentaire:

Enregistrer un commentaire