I have a project using MVP architecture. This project use the Repository pattern.
I have two data sources, the first one come from a remote JSON Api through PollutionApiService, the second is just trivial data I get from an XML file in the assets folder : air_quality_levels.xml. The network data contains real time pollution levels, the XML file contains the limits standard for these pollution levels.
For now I just have a Repository implemented for the JSON Api, it looks like this :
Interface
public interface Repository {
Observable<Aqicn> getPollutionLevelsFromNetwork(String city, String authToken);
Observable<Aqicn> getPollutionLevels(String city, String authToken);
}
Class
public class PollutionLevelsRepository implements Repository {
private PollutionApiService pollutionApiService;
private static Observable<Aqicn> pollutionData = null;
public PollutionLevelsRepository(PollutionApiService pollutionApiService) {
this.pollutionApiService = pollutionApiService;
}
@Override
public Observable<Aqicn> getPollutionLevelsFromNetwork(String city, String authToken) {
pollutionData = pollutionApiService.getPollutionObservable(city, authToken);
return pollutionData;
}
@Override
public Observable<Aqicn> getPollutionLevels(String city, String authToken) {
return getPollutionLevelsFromNetwork(city, authToken);
}
}
Should I use the same repository (adding more methods) for the data I will get from the XML file in the assets folder ?
If I have to use two repositories, How should I name this second repository interface ? I never had several repositories so I always use the generic name "Repository" for the interface. I can't give it the same name as the class and can't add a "I" prefix as I read it's bad practice... Or should I keep this "Repository" name and put the new Repository in another package ?
This is my actual project structure, note that I package by features but I put my both repositories in the common package because it gets data that will be used by my both features (donut and pollutionlevels) :
If you have short relevant suggestions about the architecture in general they are welcome.
