I would like to implement Repository
module to handle data operations. I have JSON file in row
directory and want create concrete Repository
implementation to get data from file. I'm not sure if I can use Context
as attribute in the constructor or method of Repository
.
e.g.
public class UserRepository {
UserRepository() {}
public List<User> loadUserFromFile(Context contex) {
return parseResource(context, R.raw.users);
}
}
I don't see any harm in passing the context as an attribute. If you dislike the idea then you can retrieve the context via a convenient method : Static way to get 'Context' on Android?