lundi 2 novembre 2020

CustomerDAO alternative when Customer's fields are retrieved both from a third-party web-service and application's dedicated database

I have a Customer class. Its private field is a CustomerDAO interface which database-access methods are called by myCustomer.getAge() for example. CustomerDAO retirieves data from the application's dedicated database.

The problem is that a few fields of Customer now have to be retrieved from a third-party web-service. Logically calling some web-service doesn't belong to CustomerDAO (which is intended for communicating with a single database, right?).

What is the industry recommended approach in such cases?

Shall I just add another field CustomerWebServiceDAO (as interface) to Customer? And my Customer would use internally two different instances (CustomerDAO and CustomerWebServiceDAO). So DAO gets split into 2 separate classes... What if next I need access to another Web-service plus an additional database? What better solution/pattern can be used?

Adding web-service methods to initial CustomerDAO interface would mix database access with web-service access, which I think is not good.

Aucun commentaire:

Enregistrer un commentaire