I have an application architectured by: View -> ViewModel -> Repository -> Datasource.
My DataSource is consuming a webservice and then receiving a Soap object, which I want to transform to a custom Pojo object. So, by using RxJava I am calling the DataSource method by following this flow:
ViewModel
repository.webserviceCall(data)...
.subscribe();
Repository
public Single<SoapObject> webserviceCall(String data) {
return dataSource.webserviceCall(data);
}
Datasource
public Single<SoapObject> webserviceCall(String data) {
WSSoapDAO soapDAO = new WSSoapDAO("webserviceMethodName");
soapDAO.addProperty("data", data);
return soapDAO.call();
}
and then I would like to know where should I transform the SoapObject received in the DataSource call, either in the Repository class, in the ViewModel class or in thee DataSource class itself?
In terms of your architecture I'd say the transformation should go to the repository. Let's call the entity that is to do the transformation Mapper. The mapper is supposed to transform a DTO object, SoapObject, to a model object, PojoObject.
For example
public interface Mapper {
public PojoObject map(SoapObject dto)
}
Now the presentation layer (View and ViewModel) knows nothing about DTO objects exposed by the Datasources.